-
Notifications
You must be signed in to change notification settings - Fork 42
/
Copy pathkeys.ts
100 lines (100 loc) · 3.22 KB
/
keys.ts
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
import { BinaryReader, BinaryWriter } from "../../binary";
import { bytesFromBase64, base64FromBytes } from "../../helpers";
/** PublicKey defines the keys available for use with Tendermint Validators */
export interface PublicKey {
ed25519?: Uint8Array;
secp256k1?: Uint8Array;
}
export interface PublicKeyProtoMsg {
typeUrl: "/tendermint.crypto.PublicKey";
value: Uint8Array;
}
/** PublicKey defines the keys available for use with Tendermint Validators */
export interface PublicKeyAmino {
ed25519?: string;
secp256k1?: string;
}
export interface PublicKeyAminoMsg {
type: "/tendermint.crypto.PublicKey";
value: PublicKeyAmino;
}
/** PublicKey defines the keys available for use with Tendermint Validators */
export interface PublicKeySDKType {
ed25519?: Uint8Array;
secp256k1?: Uint8Array;
}
function createBasePublicKey(): PublicKey {
return {
ed25519: undefined,
secp256k1: undefined
};
}
export const PublicKey = {
typeUrl: "/tendermint.crypto.PublicKey",
encode(message: PublicKey, writer: BinaryWriter = BinaryWriter.create()): BinaryWriter {
if (message.ed25519 !== undefined) {
writer.uint32(10).bytes(message.ed25519);
}
if (message.secp256k1 !== undefined) {
writer.uint32(18).bytes(message.secp256k1);
}
return writer;
},
decode(input: BinaryReader | Uint8Array, length?: number): PublicKey {
const reader = input instanceof BinaryReader ? input : new BinaryReader(input);
let end = length === undefined ? reader.len : reader.pos + length;
const message = createBasePublicKey();
while (reader.pos < end) {
const tag = reader.uint32();
switch (tag >>> 3) {
case 1:
message.ed25519 = reader.bytes();
break;
case 2:
message.secp256k1 = reader.bytes();
break;
default:
reader.skipType(tag & 7);
break;
}
}
return message;
},
fromPartial(object: Partial<PublicKey>): PublicKey {
const message = createBasePublicKey();
message.ed25519 = object.ed25519 ?? undefined;
message.secp256k1 = object.secp256k1 ?? undefined;
return message;
},
fromAmino(object: PublicKeyAmino): PublicKey {
const message = createBasePublicKey();
if (object.ed25519 !== undefined && object.ed25519 !== null) {
message.ed25519 = bytesFromBase64(object.ed25519);
}
if (object.secp256k1 !== undefined && object.secp256k1 !== null) {
message.secp256k1 = bytesFromBase64(object.secp256k1);
}
return message;
},
toAmino(message: PublicKey): PublicKeyAmino {
const obj: any = {};
obj.ed25519 = message.ed25519 ? base64FromBytes(message.ed25519) : undefined;
obj.secp256k1 = message.secp256k1 ? base64FromBytes(message.secp256k1) : undefined;
return obj;
},
fromAminoMsg(object: PublicKeyAminoMsg): PublicKey {
return PublicKey.fromAmino(object.value);
},
fromProtoMsg(message: PublicKeyProtoMsg): PublicKey {
return PublicKey.decode(message.value);
},
toProto(message: PublicKey): Uint8Array {
return PublicKey.encode(message).finish();
},
toProtoMsg(message: PublicKey): PublicKeyProtoMsg {
return {
typeUrl: "/tendermint.crypto.PublicKey",
value: PublicKey.encode(message).finish()
};
}
};