Skip to content

Commit 4c50ec9

Browse files
authored
deps: update protons to 5.1.0 (#175)
Remove some unused deps too.
1 parent 5200b95 commit 4c50ec9

File tree

2 files changed

+109
-21
lines changed

2 files changed

+109
-21
lines changed

package.json

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -175,21 +175,16 @@
175175
"@libp2p/logger": "^2.0.0",
176176
"@libp2p/peer-id": "^1.1.9",
177177
"cborg": "^1.3.3",
178-
"debug": "^4.2.0",
179178
"err-code": "^3.0.1",
180179
"interface-datastore": "^6.0.2",
181180
"multiformats": "^9.4.5",
182-
"protons-runtime": "^1.0.4",
181+
"protons-runtime": "^3.1.0",
183182
"timestamp-nano": "^1.0.0",
184183
"uint8arrays": "^3.0.0"
185184
},
186185
"devDependencies": {
187186
"@libp2p/peer-id-factory": "^1.0.9",
188-
"@types/debug": "^4.1.5",
189187
"aegir": "^37.0.11",
190-
"npm-run-all": "^4.1.5",
191-
"protons": "3.0.4",
192-
"rimraf": "^3.0.2",
193-
"util": "^0.12.3"
188+
"protons": "^5.1.0"
194189
}
195190
}

src/pb/ipns.ts

Lines changed: 107 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
/* eslint-disable import/export */
22
/* eslint-disable @typescript-eslint/no-namespace */
33

4-
import { enumeration, encodeMessage, decodeMessage, message, bytes, uint64 } from 'protons-runtime'
4+
import { enumeration, encodeMessage, decodeMessage, message } from 'protons-runtime'
5+
import type { Uint8ArrayList } from 'uint8arraylist'
56
import type { Codec } from 'protons-runtime'
67

78
export interface IpnsEntry {
@@ -27,29 +28,121 @@ export namespace IpnsEntry {
2728

2829
export namespace ValidityType {
2930
export const codec = () => {
30-
return enumeration<typeof ValidityType>(__ValidityTypeValues)
31+
return enumeration<ValidityType>(__ValidityTypeValues)
3132
}
3233
}
3334

35+
let _codec: Codec<IpnsEntry>
36+
3437
export const codec = (): Codec<IpnsEntry> => {
35-
return message<IpnsEntry>({
36-
1: { name: 'value', codec: bytes, optional: true },
37-
2: { name: 'signature', codec: bytes, optional: true },
38-
3: { name: 'validityType', codec: IpnsEntry.ValidityType.codec(), optional: true },
39-
4: { name: 'validity', codec: bytes, optional: true },
40-
5: { name: 'sequence', codec: uint64, optional: true },
41-
6: { name: 'ttl', codec: uint64, optional: true },
42-
7: { name: 'pubKey', codec: bytes, optional: true },
43-
8: { name: 'signatureV2', codec: bytes, optional: true },
44-
9: { name: 'data', codec: bytes, optional: true }
45-
})
38+
if (_codec == null) {
39+
_codec = message<IpnsEntry>((obj, writer, opts = {}) => {
40+
if (opts.lengthDelimited !== false) {
41+
writer.fork()
42+
}
43+
44+
if (obj.value != null) {
45+
writer.uint32(10)
46+
writer.bytes(obj.value)
47+
}
48+
49+
if (obj.signature != null) {
50+
writer.uint32(18)
51+
writer.bytes(obj.signature)
52+
}
53+
54+
if (obj.validityType != null) {
55+
writer.uint32(24)
56+
IpnsEntry.ValidityType.codec().encode(obj.validityType, writer)
57+
}
58+
59+
if (obj.validity != null) {
60+
writer.uint32(34)
61+
writer.bytes(obj.validity)
62+
}
63+
64+
if (obj.sequence != null) {
65+
writer.uint32(40)
66+
writer.uint64(obj.sequence)
67+
}
68+
69+
if (obj.ttl != null) {
70+
writer.uint32(48)
71+
writer.uint64(obj.ttl)
72+
}
73+
74+
if (obj.pubKey != null) {
75+
writer.uint32(58)
76+
writer.bytes(obj.pubKey)
77+
}
78+
79+
if (obj.signatureV2 != null) {
80+
writer.uint32(66)
81+
writer.bytes(obj.signatureV2)
82+
}
83+
84+
if (obj.data != null) {
85+
writer.uint32(74)
86+
writer.bytes(obj.data)
87+
}
88+
89+
if (opts.lengthDelimited !== false) {
90+
writer.ldelim()
91+
}
92+
}, (reader, length) => {
93+
const obj: any = {}
94+
95+
const end = length == null ? reader.len : reader.pos + length
96+
97+
while (reader.pos < end) {
98+
const tag = reader.uint32()
99+
100+
switch (tag >>> 3) {
101+
case 1:
102+
obj.value = reader.bytes()
103+
break
104+
case 2:
105+
obj.signature = reader.bytes()
106+
break
107+
case 3:
108+
obj.validityType = IpnsEntry.ValidityType.codec().decode(reader)
109+
break
110+
case 4:
111+
obj.validity = reader.bytes()
112+
break
113+
case 5:
114+
obj.sequence = reader.uint64()
115+
break
116+
case 6:
117+
obj.ttl = reader.uint64()
118+
break
119+
case 7:
120+
obj.pubKey = reader.bytes()
121+
break
122+
case 8:
123+
obj.signatureV2 = reader.bytes()
124+
break
125+
case 9:
126+
obj.data = reader.bytes()
127+
break
128+
default:
129+
reader.skipType(tag & 7)
130+
break
131+
}
132+
}
133+
134+
return obj
135+
})
136+
}
137+
138+
return _codec
46139
}
47140

48141
export const encode = (obj: IpnsEntry): Uint8Array => {
49142
return encodeMessage(obj, IpnsEntry.codec())
50143
}
51144

52-
export const decode = (buf: Uint8Array): IpnsEntry => {
145+
export const decode = (buf: Uint8Array | Uint8ArrayList): IpnsEntry => {
53146
return decodeMessage(buf, IpnsEntry.codec())
54147
}
55148
}

0 commit comments

Comments
 (0)