Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/connection-encrypter-plaintext/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,15 @@
"@libp2p/interface": "^3.1.0",
"@libp2p/peer-id": "^6.0.4",
"@libp2p/utils": "^7.0.13",
"protons-runtime": "^5.6.0",
"protons-runtime": "^6.0.1",
"uint8arraylist": "^2.4.8",
"uint8arrays": "^5.1.0"
},
"devDependencies": {
"@libp2p/crypto": "^5.1.13",
"@libp2p/logger": "^6.2.2",
"aegir": "^47.0.22",
"protons": "^7.7.0",
"protons": "^8.1.1",
"sinon": "^21.0.0"
},
"sideEffects": false
Expand Down
98 changes: 93 additions & 5 deletions packages/connection-encrypter-plaintext/src/pb/proto.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { decodeMessage, encodeMessage, enumeration, message } from 'protons-runtime'
import { decodeMessage, encodeMessage, enumeration, message, streamMessage } from 'protons-runtime'
import { alloc as uint8ArrayAlloc } from 'uint8arrays/alloc'
import type { Codec, DecodeOptions } from 'protons-runtime'
import type { Uint8ArrayList } from 'uint8arraylist'
Expand Down Expand Up @@ -58,19 +58,65 @@ export namespace Exchange {
}

return obj
}, function * (reader, length, prefix, opts = {}) {
const end = length == null ? reader.len : reader.pos + length

while (reader.pos < end) {
const tag = reader.uint32()

switch (tag >>> 3) {
case 1: {
yield {
field: `${prefix}.id`,
value: reader.bytes()
}
break
}
case 2: {
yield * PublicKey.codec().stream(reader, reader.uint32(), `${prefix}.pubkey`, {
limits: opts.limits?.pubkey
})

break
}
default: {
reader.skipType(tag & 7)
break
}
}
}
})
}

return _codec
}

export const encode = (obj: Partial<Exchange>): Uint8Array => {
export interface ExchangeIdFieldEvent {
field: '$.id'
value: Uint8Array
}

export interface ExchangePubkeyTypeFieldEvent {
field: '$.pubkey.Type'
value: KeyType
}

export interface ExchangePubkeyDataFieldEvent {
field: '$.pubkey.Data'
value: Uint8Array
}

export function encode (obj: Partial<Exchange>): Uint8Array {
return encodeMessage(obj, Exchange.codec())
}

export const decode = (buf: Uint8Array | Uint8ArrayList, opts?: DecodeOptions<Exchange>): Exchange => {
export function decode (buf: Uint8Array | Uint8ArrayList, opts?: DecodeOptions<Exchange>): Exchange {
return decodeMessage(buf, Exchange.codec(), opts)
}

export function stream (buf: Uint8Array | Uint8ArrayList, opts?: DecodeOptions<Exchange>): Generator<ExchangeIdFieldEvent | ExchangePubkeyTypeFieldEvent | ExchangePubkeyDataFieldEvent> {
return streamMessage(buf, Exchange.codec(), opts)
}
}

export enum KeyType {
Expand All @@ -92,6 +138,7 @@ export namespace KeyType {
return enumeration<KeyType>(__KeyTypeValues)
}
}

export interface PublicKey {
Type?: KeyType
Data: Uint8Array
Expand Down Expand Up @@ -147,17 +194,58 @@ export namespace PublicKey {
}

return obj
}, function * (reader, length, prefix, opts = {}) {
const end = length == null ? reader.len : reader.pos + length

while (reader.pos < end) {
const tag = reader.uint32()

switch (tag >>> 3) {
case 1: {
yield {
field: `${prefix}.Type`,
value: KeyType.codec().decode(reader)
}
break
}
case 2: {
yield {
field: `${prefix}.Data`,
value: reader.bytes()
}
break
}
default: {
reader.skipType(tag & 7)
break
}
}
}
})
}

return _codec
}

export const encode = (obj: Partial<PublicKey>): Uint8Array => {
export interface PublicKeyTypeFieldEvent {
field: '$.Type'
value: KeyType
}

export interface PublicKeyDataFieldEvent {
field: '$.Data'
value: Uint8Array
}

export function encode (obj: Partial<PublicKey>): Uint8Array {
return encodeMessage(obj, PublicKey.codec())
}

export const decode = (buf: Uint8Array | Uint8ArrayList, opts?: DecodeOptions<PublicKey>): PublicKey => {
export function decode (buf: Uint8Array | Uint8ArrayList, opts?: DecodeOptions<PublicKey>): PublicKey {
return decodeMessage(buf, PublicKey.codec(), opts)
}

export function stream (buf: Uint8Array | Uint8ArrayList, opts?: DecodeOptions<PublicKey>): Generator<PublicKeyTypeFieldEvent | PublicKeyDataFieldEvent> {
return streamMessage(buf, PublicKey.codec(), opts)
}
}
4 changes: 2 additions & 2 deletions packages/connection-encrypter-tls/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,14 @@
"@peculiar/x509": "^1.13.0",
"asn1js": "^3.0.6",
"p-event": "^7.0.0",
"protons-runtime": "^5.6.0",
"protons-runtime": "^6.0.1",
"uint8arraylist": "^2.4.8",
"uint8arrays": "^5.1.0"
},
"devDependencies": {
"@libp2p/logger": "^6.2.2",
"aegir": "^47.0.22",
"protons": "^7.7.0",
"protons": "^8.1.1",
"sinon": "^21.0.0",
"sinon-ts": "^2.0.0"
},
Expand Down
48 changes: 45 additions & 3 deletions packages/connection-encrypter-tls/src/pb/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { decodeMessage, encodeMessage, enumeration, message } from 'protons-runtime'
import { decodeMessage, encodeMessage, enumeration, message, streamMessage } from 'protons-runtime'
import type { Codec, DecodeOptions } from 'protons-runtime'
import type { Uint8ArrayList } from 'uint8arraylist'

Expand All @@ -21,6 +21,7 @@ export namespace KeyType {
return enumeration<KeyType>(__KeyTypeValues)
}
}

export interface PublicKey {
type?: KeyType
data?: Uint8Array
Expand Down Expand Up @@ -74,17 +75,58 @@ export namespace PublicKey {
}

return obj
}, function * (reader, length, prefix, opts = {}) {
const end = length == null ? reader.len : reader.pos + length

while (reader.pos < end) {
const tag = reader.uint32()

switch (tag >>> 3) {
case 1: {
yield {
field: `${prefix}.type`,
value: KeyType.codec().decode(reader)
}
break
}
case 2: {
yield {
field: `${prefix}.data`,
value: reader.bytes()
}
break
}
default: {
reader.skipType(tag & 7)
break
}
}
}
})
}

return _codec
}

export const encode = (obj: Partial<PublicKey>): Uint8Array => {
export interface PublicKeyTypeFieldEvent {
field: '$.type'
value: KeyType
}

export interface PublicKeyDataFieldEvent {
field: '$.data'
value: Uint8Array
}

export function encode (obj: Partial<PublicKey>): Uint8Array {
return encodeMessage(obj, PublicKey.codec())
}

export const decode = (buf: Uint8Array | Uint8ArrayList, opts?: DecodeOptions<PublicKey>): PublicKey => {
export function decode (buf: Uint8Array | Uint8ArrayList, opts?: DecodeOptions<PublicKey>): PublicKey {
return decodeMessage(buf, PublicKey.codec(), opts)
}

export function stream (buf: Uint8Array | Uint8ArrayList, opts?: DecodeOptions<PublicKey>): Generator<PublicKeyTypeFieldEvent | PublicKeyDataFieldEvent> {
return streamMessage(buf, PublicKey.codec(), opts)
}
}
4 changes: 2 additions & 2 deletions packages/crypto/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@
"@noble/curves": "^2.0.1",
"@noble/hashes": "^2.0.1",
"multiformats": "^13.4.0",
"protons-runtime": "^5.6.0",
"protons-runtime": "^6.0.1",
"uint8arraylist": "^2.4.8",
"uint8arrays": "^5.1.0"
},
Expand All @@ -98,7 +98,7 @@
"aegir": "^47.0.22",
"asn1js": "^3.0.6",
"benchmark": "^2.1.4",
"protons": "^7.7.0"
"protons": "^8.1.1"
},
"browser": {
"./dist/src/ciphers/aes-gcm.js": "./dist/src/ciphers/aes-gcm.browser.js",
Expand Down
Loading
Loading