-
Notifications
You must be signed in to change notification settings - Fork 520
Expand file tree
/
Copy pathindex.ts
More file actions
132 lines (111 loc) · 3.11 KB
/
index.ts
File metadata and controls
132 lines (111 loc) · 3.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
import { decodeMessage, encodeMessage, enumeration, message, streamMessage } from 'protons-runtime'
import type { Codec, DecodeOptions } from 'protons-runtime'
import type { Uint8ArrayList } from 'uint8arraylist'
export enum KeyType {
RSA = 'RSA',
Ed25519 = 'Ed25519',
secp256k1 = 'secp256k1',
ECDSA = 'ECDSA'
}
enum __KeyTypeValues {
RSA = 0,
Ed25519 = 1,
secp256k1 = 2,
ECDSA = 3
}
export namespace KeyType {
export const codec = (): Codec<KeyType> => {
return enumeration<KeyType>(__KeyTypeValues)
}
}
export interface PublicKey {
type?: KeyType
data?: Uint8Array
}
export namespace PublicKey {
let _codec: Codec<PublicKey>
export const codec = (): Codec<PublicKey> => {
if (_codec == null) {
_codec = message<PublicKey>((obj, w, opts = {}) => {
if (opts.lengthDelimited !== false) {
w.fork()
}
if (obj.type != null) {
w.uint32(8)
KeyType.codec().encode(obj.type, w)
}
if (obj.data != null) {
w.uint32(18)
w.bytes(obj.data)
}
if (opts.lengthDelimited !== false) {
w.ldelim()
}
}, (reader, length, opts = {}) => {
const obj: any = {}
const end = length == null ? reader.len : reader.pos + length
while (reader.pos < end) {
const tag = reader.uint32()
switch (tag >>> 3) {
case 1: {
obj.type = KeyType.codec().decode(reader)
break
}
case 2: {
obj.data = reader.bytes()
break
}
default: {
reader.skipType(tag & 7)
break
}
}
}
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 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 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)
}
}