2022-04-09 09:26:25 +01:00
|
|
|
/* eslint-disable import/export */
|
|
|
|
/* eslint-disable @typescript-eslint/no-namespace */
|
|
|
|
|
2022-08-11 13:21:04 +01:00
|
|
|
import { encodeMessage, decodeMessage, message, enumeration } from 'protons-runtime'
|
2022-08-03 14:15:35 +01:00
|
|
|
import type { Uint8ArrayList } from 'uint8arraylist'
|
2022-08-11 13:21:04 +01:00
|
|
|
import type { Codec } from 'protons-runtime'
|
2022-04-09 09:26:25 +01:00
|
|
|
|
|
|
|
export interface Exchange {
|
|
|
|
id?: Uint8Array
|
|
|
|
pubkey?: PublicKey
|
|
|
|
}
|
|
|
|
|
|
|
|
export namespace Exchange {
|
2022-08-11 13:21:04 +01:00
|
|
|
let _codec: Codec<Exchange>
|
|
|
|
|
2022-05-10 12:35:33 +01:00
|
|
|
export const codec = (): Codec<Exchange> => {
|
2022-08-11 13:21:04 +01:00
|
|
|
if (_codec == null) {
|
|
|
|
_codec = message<Exchange>((obj, writer, opts = {}) => {
|
|
|
|
if (opts.lengthDelimited !== false) {
|
|
|
|
writer.fork()
|
|
|
|
}
|
|
|
|
|
|
|
|
if (obj.id != null) {
|
|
|
|
writer.uint32(10)
|
|
|
|
writer.bytes(obj.id)
|
|
|
|
}
|
|
|
|
|
|
|
|
if (obj.pubkey != null) {
|
|
|
|
writer.uint32(18)
|
|
|
|
PublicKey.codec().encode(obj.pubkey, writer)
|
|
|
|
}
|
|
|
|
|
|
|
|
if (opts.lengthDelimited !== false) {
|
|
|
|
writer.ldelim()
|
|
|
|
}
|
|
|
|
}, (reader, length) => {
|
|
|
|
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.id = reader.bytes()
|
|
|
|
break
|
|
|
|
case 2:
|
|
|
|
obj.pubkey = PublicKey.codec().decode(reader, reader.uint32())
|
|
|
|
break
|
|
|
|
default:
|
|
|
|
reader.skipType(tag & 7)
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return obj
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
return _codec
|
2022-04-09 09:26:25 +01:00
|
|
|
}
|
|
|
|
|
2022-08-11 13:21:04 +01:00
|
|
|
export const encode = (obj: Exchange): Uint8Array => {
|
2022-04-09 09:26:25 +01:00
|
|
|
return encodeMessage(obj, Exchange.codec())
|
|
|
|
}
|
|
|
|
|
2022-08-03 14:15:35 +01:00
|
|
|
export const decode = (buf: Uint8Array | Uint8ArrayList): Exchange => {
|
2022-04-09 09:26:25 +01:00
|
|
|
return decodeMessage(buf, Exchange.codec())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export enum KeyType {
|
|
|
|
RSA = 'RSA',
|
|
|
|
Ed25519 = 'Ed25519',
|
|
|
|
Secp256k1 = 'Secp256k1',
|
|
|
|
ECDSA = 'ECDSA'
|
|
|
|
}
|
|
|
|
|
2022-05-10 12:35:33 +01:00
|
|
|
enum __KeyTypeValues {
|
|
|
|
RSA = 0,
|
|
|
|
Ed25519 = 1,
|
|
|
|
Secp256k1 = 2,
|
|
|
|
ECDSA = 3
|
|
|
|
}
|
|
|
|
|
2022-04-09 09:26:25 +01:00
|
|
|
export namespace KeyType {
|
|
|
|
export const codec = () => {
|
2022-08-11 13:21:04 +01:00
|
|
|
return enumeration<KeyType>(__KeyTypeValues)
|
2022-04-09 09:26:25 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
export interface PublicKey {
|
|
|
|
Type: KeyType
|
|
|
|
Data: Uint8Array
|
|
|
|
}
|
|
|
|
|
|
|
|
export namespace PublicKey {
|
2022-08-11 13:21:04 +01:00
|
|
|
let _codec: Codec<PublicKey>
|
|
|
|
|
2022-05-10 12:35:33 +01:00
|
|
|
export const codec = (): Codec<PublicKey> => {
|
2022-08-11 13:21:04 +01:00
|
|
|
if (_codec == null) {
|
|
|
|
_codec = message<PublicKey>((obj, writer, opts = {}) => {
|
|
|
|
if (opts.lengthDelimited !== false) {
|
|
|
|
writer.fork()
|
|
|
|
}
|
|
|
|
|
|
|
|
if (obj.Type != null) {
|
|
|
|
writer.uint32(8)
|
|
|
|
KeyType.codec().encode(obj.Type, writer)
|
|
|
|
} else {
|
|
|
|
throw new Error('Protocol error: required field "Type" was not found in object')
|
|
|
|
}
|
|
|
|
|
|
|
|
if (obj.Data != null) {
|
|
|
|
writer.uint32(18)
|
|
|
|
writer.bytes(obj.Data)
|
|
|
|
} else {
|
|
|
|
throw new Error('Protocol error: required field "Data" was not found in object')
|
|
|
|
}
|
|
|
|
|
|
|
|
if (opts.lengthDelimited !== false) {
|
|
|
|
writer.ldelim()
|
|
|
|
}
|
|
|
|
}, (reader, length) => {
|
|
|
|
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
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (obj.Type == null) {
|
|
|
|
throw new Error('Protocol error: value for required field "Type" was not found in protobuf')
|
|
|
|
}
|
|
|
|
|
|
|
|
if (obj.Data == null) {
|
|
|
|
throw new Error('Protocol error: value for required field "Data" was not found in protobuf')
|
|
|
|
}
|
|
|
|
|
|
|
|
return obj
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
return _codec
|
2022-04-09 09:26:25 +01:00
|
|
|
}
|
|
|
|
|
2022-08-11 13:21:04 +01:00
|
|
|
export const encode = (obj: PublicKey): Uint8Array => {
|
2022-04-09 09:26:25 +01:00
|
|
|
return encodeMessage(obj, PublicKey.codec())
|
|
|
|
}
|
|
|
|
|
2022-08-03 14:15:35 +01:00
|
|
|
export const decode = (buf: Uint8Array | Uint8ArrayList): PublicKey => {
|
2022-04-09 09:26:25 +01:00
|
|
|
return decodeMessage(buf, PublicKey.codec())
|
|
|
|
}
|
|
|
|
}
|