From 1ad7eeea91e6e203e1a3627ef4d535f3fea4df96 Mon Sep 17 00:00:00 2001 From: Zakaria Lounes Date: Fri, 4 Mar 2022 10:27:31 +0100 Subject: [PATCH] EthSecp --- src/cosmos/crypto/ethsecp256k1/keys.ts | 177 +++++++++++++++++++++++++ 1 file changed, 177 insertions(+) create mode 100644 src/cosmos/crypto/ethsecp256k1/keys.ts diff --git a/src/cosmos/crypto/ethsecp256k1/keys.ts b/src/cosmos/crypto/ethsecp256k1/keys.ts new file mode 100644 index 00000000..4da4587c --- /dev/null +++ b/src/cosmos/crypto/ethsecp256k1/keys.ts @@ -0,0 +1,177 @@ +/* eslint-disable */ +import Long from "long"; +import _m0 from "protobufjs/minimal"; + +export const protobufPackage = "ethermint.crypto.v1.ethsecp256k1"; + +/** + * PubKey defines a secp256k1 public key + * Key is the compressed form of the pubkey. The first byte depends is a 0x02 byte + * if the y-coordinate is the lexicographically largest of the two associated with + * the x-coordinate. Otherwise the first byte is a 0x03. + * This prefix is followed with the x-coordinate. + */ +export interface PubKey { + key: Uint8Array; +} + +/** PrivKey defines a ethsecp256k1 private key. */ +export interface PrivKey { + key: Uint8Array; +} + +const basePubKey: object = {}; + +export const PubKey = { + encode(message: PubKey, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer { + if (message.key.length !== 0) { + writer.uint32(10).bytes(message.key); + } + return writer; + }, + + decode(input: _m0.Reader | Uint8Array, length?: number): PubKey { + const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input); + let end = length === undefined ? reader.len : reader.pos + length; + const message = { ...basePubKey } as PubKey; + message.key = new Uint8Array(); + while (reader.pos < end) { + const tag = reader.uint32(); + switch (tag >>> 3) { + case 1: + message.key = reader.bytes(); + break; + default: + reader.skipType(tag & 7); + break; + } + } + return message; + }, + + fromJSON(object: any): PubKey { + const message = { ...basePubKey } as PubKey; + message.key = + object.key !== undefined && object.key !== null ? bytesFromBase64(object.key) : new Uint8Array(); + return message; + }, + + toJSON(message: PubKey): unknown { + const obj: any = {}; + message.key !== undefined && + (obj.key = base64FromBytes(message.key !== undefined ? message.key : new Uint8Array())); + return obj; + }, + + fromPartial, I>>(object: I): PubKey { + const message = { ...basePubKey } as PubKey; + message.key = object.key ?? new Uint8Array(); + return message; + }, +}; + +const basePrivKey: object = {}; + +export const PrivKey = { + encode(message: PrivKey, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer { + if (message.key.length !== 0) { + writer.uint32(10).bytes(message.key); + } + return writer; + }, + + decode(input: _m0.Reader | Uint8Array, length?: number): PrivKey { + const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input); + let end = length === undefined ? reader.len : reader.pos + length; + const message = { ...basePrivKey } as PrivKey; + message.key = new Uint8Array(); + while (reader.pos < end) { + const tag = reader.uint32(); + switch (tag >>> 3) { + case 1: + message.key = reader.bytes(); + break; + default: + reader.skipType(tag & 7); + break; + } + } + return message; + }, + + fromJSON(object: any): PrivKey { + const message = { ...basePrivKey } as PrivKey; + message.key = + object.key !== undefined && object.key !== null ? bytesFromBase64(object.key) : new Uint8Array(); + return message; + }, + + toJSON(message: PrivKey): unknown { + const obj: any = {}; + message.key !== undefined && + (obj.key = base64FromBytes(message.key !== undefined ? message.key : new Uint8Array())); + return obj; + }, + + fromPartial, I>>(object: I): PrivKey { + const message = { ...basePrivKey } as PrivKey; + message.key = object.key ?? new Uint8Array(); + return message; + }, +}; + +declare var self: any | undefined; +declare var window: any | undefined; +declare var global: any | undefined; +var globalThis: any = (() => { + if (typeof globalThis !== "undefined") return globalThis; + if (typeof self !== "undefined") return self; + if (typeof window !== "undefined") return window; + if (typeof global !== "undefined") return global; + throw "Unable to locate global object"; +})(); + +const atob: (b64: string) => string = + globalThis.atob || ((b64) => globalThis.Buffer.from(b64, "base64").toString("binary")); +function bytesFromBase64(b64: string): Uint8Array { + const bin = atob(b64); + const arr = new Uint8Array(bin.length); + for (let i = 0; i < bin.length; ++i) { + arr[i] = bin.charCodeAt(i); + } + return arr; +} + +const btoa: (bin: string) => string = + globalThis.btoa || ((bin) => globalThis.Buffer.from(bin, "binary").toString("base64")); +function base64FromBytes(arr: Uint8Array): string { + const bin: string[] = []; + for (const byte of arr) { + bin.push(String.fromCharCode(byte)); + } + return btoa(bin.join("")); +} + +type Builtin = Date | Function | Uint8Array | string | number | boolean | undefined; + +export type DeepPartial = T extends Builtin + ? T + : T extends Long + ? string | number | Long + : T extends Array + ? Array> + : T extends ReadonlyArray + ? ReadonlyArray> + : T extends {} + ? { [K in keyof T]?: DeepPartial } + : Partial; + +type KeysOfUnion = T extends T ? keyof T : never; +export type Exact = P extends Builtin + ? P + : P & { [K in keyof P]: Exact } & Record>, never>; + +if (_m0.util.Long !== Long) { + _m0.util.Long = Long as any; + _m0.configure(); +}