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

Commit

Permalink
fix: regenerate protobuf code (#212)
Browse files Browse the repository at this point in the history
Regenerates with return types
  • Loading branch information
achingbrain committed May 10, 2022
1 parent ea8b08c commit 3cf210e
Show file tree
Hide file tree
Showing 11 changed files with 42 additions and 32 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
"test:electron-main": "lerna run --concurrency 1 test:electron-main -- --",
"test:electron-renderer": "lerna run --concurrency 1 test:electron-renderer -- --",
"clean": "lerna run clean",
"generate": "lerna run generate",
"build": "lerna run build",
"lint": "lerna run lint",
"dep-check": "lerna run dep-check",
Expand Down
5 changes: 3 additions & 2 deletions packages/libp2p-peer-id-factory/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@
"clean": "aegir clean",
"lint": "aegir lint",
"dep-check": "aegir dep-check",
"generate": "protons src/proto.proto",
"build": "aegir build",
"test": "aegir test",
"test:chrome": "aegir test -t browser --cov",
Expand All @@ -141,12 +142,12 @@
"@libp2p/interfaces": "^1.3.0",
"@libp2p/peer-id": "^1.1.0",
"multiformats": "^9.6.3",
"protons-runtime": "^1.0.2",
"protons-runtime": "^1.0.4",
"uint8arrays": "^3.0.0"
},
"devDependencies": {
"aegir": "^37.0.7",
"protons": "^3.0.2",
"protons": "^3.0.4",
"util": "^0.12.4"
}
}
16 changes: 8 additions & 8 deletions packages/libp2p-peer-id-factory/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { keys } from '@libp2p/crypto'
import { generateKeyPair, marshalPrivateKey, unmarshalPrivateKey, marshalPublicKey, unmarshalPublicKey } from '@libp2p/crypto/keys'
import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string'
import { peerIdFromKeys, peerIdFromBytes } from '@libp2p/peer-id'
import { PeerIdProto } from './proto.js'
import type { PublicKey, PrivateKey } from '@libp2p/interfaces/keys'
import type { RSAPeerId, Ed25519PeerId, Secp256k1PeerId } from '@libp2p/interfaces/peer-id'

export const createEd25519PeerId = async (): Promise<Ed25519PeerId> => {
const key = await keys.generateKeyPair('Ed25519')
const key = await generateKeyPair('Ed25519')
const id = await createFromPrivKey(key)

if (id.type === 'Ed25519') {
Expand All @@ -17,7 +17,7 @@ export const createEd25519PeerId = async (): Promise<Ed25519PeerId> => {
}

export const createSecp256k1PeerId = async (): Promise<Secp256k1PeerId> => {
const key = await keys.generateKeyPair('secp256k1')
const key = await generateKeyPair('secp256k1')
const id = await createFromPrivKey(key)

if (id.type === 'secp256k1') {
Expand All @@ -28,7 +28,7 @@ export const createSecp256k1PeerId = async (): Promise<Secp256k1PeerId> => {
}

export const createRSAPeerId = async (opts?: { bits: number }): Promise<RSAPeerId> => {
const key = await keys.generateKeyPair('RSA', opts?.bits ?? 2048)
const key = await generateKeyPair('RSA', opts?.bits ?? 2048)
const id = await createFromPrivKey(key)

if (id.type === 'RSA') {
Expand All @@ -39,11 +39,11 @@ export const createRSAPeerId = async (opts?: { bits: number }): Promise<RSAPeerI
}

export async function createFromPubKey (publicKey: PublicKey) {
return await peerIdFromKeys(keys.marshalPublicKey(publicKey))
return await peerIdFromKeys(marshalPublicKey(publicKey))
}

export async function createFromPrivKey (privateKey: PrivateKey) {
return await peerIdFromKeys(keys.marshalPublicKey(privateKey.public), keys.marshalPrivateKey(privateKey))
return await peerIdFromKeys(marshalPublicKey(privateKey.public), marshalPrivateKey(privateKey))
}

export function exportToProtobuf (peerId: RSAPeerId | Ed25519PeerId | Secp256k1PeerId, excludePrivateKey?: boolean) {
Expand Down Expand Up @@ -78,11 +78,11 @@ export async function createFromJSON (obj: { id: string, privKey?: string, pubKe

async function createFromParts (multihash: Uint8Array, privKey?: Uint8Array, pubKey?: Uint8Array) {
if (privKey != null) {
const key = await keys.unmarshalPrivateKey(privKey)
const key = await unmarshalPrivateKey(privKey)

return await createFromPrivKey(key)
} else if (pubKey != null) {
const key = await keys.unmarshalPublicKey(pubKey)
const key = await unmarshalPublicKey(pubKey)

return await createFromPubKey(key)
}
Expand Down
3 changes: 2 additions & 1 deletion packages/libp2p-peer-id-factory/src/proto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
/* eslint-disable @typescript-eslint/no-namespace */

import { encodeMessage, decodeMessage, message, bytes } from 'protons-runtime'
import type { Codec } from 'protons-runtime'

export interface PeerIdProto {
id: Uint8Array
Expand All @@ -10,7 +11,7 @@ export interface PeerIdProto {
}

export namespace PeerIdProto {
export const codec = () => {
export const codec = (): Codec<PeerIdProto> => {
return message<PeerIdProto>({
1: { name: 'id', codec: bytes },
2: { name: 'pubKey', codec: bytes, optional: true },
Expand Down
5 changes: 3 additions & 2 deletions packages/libp2p-peer-record/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@
"clean": "aegir clean",
"lint": "aegir lint",
"dep-check": "aegir dep-check",
"generate": "protons src/envelope/envelope.proto src/peer-record/peer-record.proto",
"build": "aegir build",
"test": "aegir test",
"test:chrome": "aegir test -t browser --cov",
Expand All @@ -153,7 +154,7 @@
"it-map": "^1.0.6",
"it-pipe": "^2.0.3",
"multiformats": "^9.6.3",
"protons-runtime": "^1.0.2",
"protons-runtime": "^1.0.4",
"uint8arrays": "^3.0.0",
"varint": "^6.0.0"
},
Expand All @@ -162,7 +163,7 @@
"@libp2p/peer-id-factory": "^1.0.0",
"@types/varint": "^6.0.0",
"aegir": "^37.0.7",
"protons": "^3.0.2",
"protons": "^3.0.4",
"sinon": "^13.0.1"
}
}
3 changes: 2 additions & 1 deletion packages/libp2p-peer-record/src/envelope/envelope.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
/* eslint-disable @typescript-eslint/no-namespace */

import { encodeMessage, decodeMessage, message, bytes } from 'protons-runtime'
import type { Codec } from 'protons-runtime'

export interface Envelope {
publicKey: Uint8Array
Expand All @@ -11,7 +12,7 @@ export interface Envelope {
}

export namespace Envelope {
export const codec = () => {
export const codec = (): Codec<Envelope> => {
return message<Envelope>({
1: { name: 'publicKey', codec: bytes },
2: { name: 'payloadType', codec: bytes },
Expand Down
5 changes: 3 additions & 2 deletions packages/libp2p-peer-record/src/peer-record/peer-record.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
/* eslint-disable @typescript-eslint/no-namespace */

import { encodeMessage, decodeMessage, message, bytes, uint64 } from 'protons-runtime'
import type { Codec } from 'protons-runtime'

export interface PeerRecord {
peerId: Uint8Array
Expand All @@ -15,7 +16,7 @@ export namespace PeerRecord {
}

export namespace AddressInfo {
export const codec = () => {
export const codec = (): Codec<AddressInfo> => {
return message<AddressInfo>({
1: { name: 'multiaddr', codec: bytes }
})
Expand All @@ -30,7 +31,7 @@ export namespace PeerRecord {
}
}

export const codec = () => {
export const codec = (): Codec<PeerRecord> => {
return message<PeerRecord>({
1: { name: 'peerId', codec: bytes },
2: { name: 'seq', codec: uint64 },
Expand Down
5 changes: 3 additions & 2 deletions packages/libp2p-peer-store/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@
"clean": "aegir clean",
"lint": "aegir lint",
"dep-check": "aegir dep-check",
"generate": "protons src/pb/peer.proto",
"build": "aegir build",
"test": "aegir test",
"test:chrome": "aegir test -t browser --cov",
Expand All @@ -151,7 +152,7 @@
"it-pipe": "^2.0.3",
"mortice": "^3.0.0",
"multiformats": "^9.6.3",
"protons-runtime": "^1.0.2",
"protons-runtime": "^1.0.4",
"uint8arrays": "^3.0.0"
},
"devDependencies": {
Expand All @@ -162,7 +163,7 @@
"datastore-core": "^7.0.1",
"p-defer": "^4.0.0",
"p-wait-for": "^4.1.0",
"protons": "^3.0.2",
"protons": "^3.0.4",
"sinon": "^13.0.1"
}
}
7 changes: 4 additions & 3 deletions packages/libp2p-peer-store/src/pb/peer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
/* eslint-disable @typescript-eslint/no-namespace */

import { encodeMessage, decodeMessage, message, string, bytes, bool } from 'protons-runtime'
import type { Codec } from 'protons-runtime'

export interface Peer {
addresses: Address[]
Expand All @@ -12,7 +13,7 @@ export interface Peer {
}

export namespace Peer {
export const codec = () => {
export const codec = (): Codec<Peer> => {
return message<Peer>({
1: { name: 'addresses', codec: Address.codec(), repeats: true },
2: { name: 'protocols', codec: string, repeats: true },
Expand All @@ -37,7 +38,7 @@ export interface Address {
}

export namespace Address {
export const codec = () => {
export const codec = (): Codec<Address> => {
return message<Address>({
1: { name: 'multiaddr', codec: bytes },
2: { name: 'isCertified', codec: bool, optional: true }
Expand All @@ -59,7 +60,7 @@ export interface Metadata {
}

export namespace Metadata {
export const codec = () => {
export const codec = (): Codec<Metadata> => {
return message<Metadata>({
1: { name: 'key', codec: string },
2: { name: 'value', codec: bytes }
Expand Down
4 changes: 2 additions & 2 deletions packages/libp2p-pubsub/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -196,8 +196,8 @@
"it-pair": "^2.0.2",
"p-defer": "^4.0.0",
"p-wait-for": "^4.1.0",
"protons": "^3.0.2",
"protons-runtime": "^1.0.2",
"protons": "^3.0.4",
"protons-runtime": "^1.0.4",
"sinon": "^13.0.1",
"util": "^0.12.4"
}
Expand Down
20 changes: 11 additions & 9 deletions packages/libp2p-pubsub/test/message/rpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
/* eslint-disable @typescript-eslint/no-namespace */

import { encodeMessage, decodeMessage, message, bool, string, bytes, uint64 } from 'protons-runtime'
import type { Codec } from 'protons-runtime'

export interface RPC {
subscriptions: RPC.SubOpts[]
Expand All @@ -16,7 +17,7 @@ export namespace RPC {
}

export namespace SubOpts {
export const codec = () => {
export const codec = (): Codec<SubOpts> => {
return message<SubOpts>({
1: { name: 'subscribe', codec: bool, optional: true },
2: { name: 'topic', codec: string, optional: true }
Expand All @@ -31,6 +32,7 @@ export namespace RPC {
return decodeMessage(buf, SubOpts.codec())
}
}

export interface Message {
from?: Uint8Array
data?: Uint8Array
Expand All @@ -41,7 +43,7 @@ export namespace RPC {
}

export namespace Message {
export const codec = () => {
export const codec = (): Codec<Message> => {
return message<Message>({
1: { name: 'from', codec: bytes, optional: true },
2: { name: 'data', codec: bytes, optional: true },
Expand All @@ -61,7 +63,7 @@ export namespace RPC {
}
}

export const codec = () => {
export const codec = (): Codec<RPC> => {
return message<RPC>({
1: { name: 'subscriptions', codec: RPC.SubOpts.codec(), repeats: true },
2: { name: 'messages', codec: RPC.Message.codec(), repeats: true },
Expand All @@ -86,7 +88,7 @@ export interface ControlMessage {
}

export namespace ControlMessage {
export const codec = () => {
export const codec = (): Codec<ControlMessage> => {
return message<ControlMessage>({
1: { name: 'ihave', codec: ControlIHave.codec(), repeats: true },
2: { name: 'iwant', codec: ControlIWant.codec(), repeats: true },
Expand All @@ -110,7 +112,7 @@ export interface ControlIHave {
}

export namespace ControlIHave {
export const codec = () => {
export const codec = (): Codec<ControlIHave> => {
return message<ControlIHave>({
1: { name: 'topic', codec: string, optional: true },
2: { name: 'messageIDs', codec: bytes, repeats: true }
Expand All @@ -131,7 +133,7 @@ export interface ControlIWant {
}

export namespace ControlIWant {
export const codec = () => {
export const codec = (): Codec<ControlIWant> => {
return message<ControlIWant>({
1: { name: 'messageIDs', codec: bytes, repeats: true }
})
Expand All @@ -151,7 +153,7 @@ export interface ControlGraft {
}

export namespace ControlGraft {
export const codec = () => {
export const codec = (): Codec<ControlGraft> => {
return message<ControlGraft>({
1: { name: 'topic', codec: string, optional: true }
})
Expand All @@ -173,7 +175,7 @@ export interface ControlPrune {
}

export namespace ControlPrune {
export const codec = () => {
export const codec = (): Codec<ControlPrune> => {
return message<ControlPrune>({
1: { name: 'topic', codec: string, optional: true },
2: { name: 'peers', codec: PeerInfo.codec(), repeats: true },
Expand All @@ -196,7 +198,7 @@ export interface PeerInfo {
}

export namespace PeerInfo {
export const codec = () => {
export const codec = (): Codec<PeerInfo> => {
return message<PeerInfo>({
1: { name: 'peerID', codec: bytes, optional: true },
2: { name: 'signedPeerRecord', codec: bytes, optional: true }
Expand Down

0 comments on commit 3cf210e

Please sign in to comment.