// @generated by protobuf-ts 2.9.0
// @generated from protobuf file "signature.proto" (package "pb", syntax proto3)
// tslint:disable
import type { BinaryWriteOptions } from "@protobuf-ts/runtime";
import type { IBinaryWriter } from "@protobuf-ts/runtime";
import { WireType } from "@protobuf-ts/runtime";
import type { BinaryReadOptions } from "@protobuf-ts/runtime";
import type { IBinaryReader } from "@protobuf-ts/runtime";
import { UnknownFieldHandler } from "@protobuf-ts/runtime";
import type { PartialMessage } from "@protobuf-ts/runtime";
import { reflectionMergePartial } from "@protobuf-ts/runtime";
import { MESSAGE_TYPE } from "@protobuf-ts/runtime";
import { MessageType } from "@protobuf-ts/runtime";
/**
*
* A signature and details to help verify it.
*
* #### Generation
*
* - Compute a CID from the `piece` bytes using details from `signature`:
* - [CIDv1](https://github.com/multiformats/cid).
* - The hash function should be blake2b-256 and `multiHashType` should be empty.
* - Content type codec `0x55`
* - Base encoded in Base32 with the prefix `b`
* - Example: bafk2bzacea73ycjnxe2qov7cvnhx52lzfp6nf5jcblnfus6gqreh6ygganbws
*
* - Store the public key of the signer in `publicKey` in binary encoding.
*
* - Store the current time in `timestamp`
* - In JavaScript: `timestamp = +new Date()`
*
* - Format the current time in ISO 8601 `YYYY-MM-DDTHH:mm:ss.sssZ`
* - In JavaScript: `timeText = new Date(timestamp).toISOString()`
* - In Go format: `2006-01-02T15:04:05.000Z`
*
* - The signed message to store a piece is:
* - `DDC store ${CID} at ${timeText}`
* - Note: the `` part is enforced by the Polkadot.js browser extension.
* - Example: `DDC store bafk2bzacea73ycjnxe2qov7cvnhx52lzfp6nf5jcblnfus6gqreh6ygganbws at 2022-06-27T07:33:44.607Z`
*
* - The signing scheme should be sr25519, and `scheme` should be empty.
* - If this not supported by a signer, then `scheme` should be "ed25519".
*
* - Sign and store the signature in `sig` in binary encoding.
*
* #### Verification
*
* - Recompute the signed message using the details in `signature`.
* - Verify `sig` given the scheme, the message, and the public key.
*
* #### Legacy signatures before v0.1.4
*
* If `timestamp == 0`, assume an older version:
* - Decode `value` and `signer` from hexadecimal with or without `0x`.
* - Then the signed message is either `${CID}` or `${CID}`.
*
*
* @generated from protobuf message pb.Signature
*/
export interface Signature {
/**
* The cryptographic signature in binary encoding as per the scheme.
*
* @generated from protobuf field: bytes value = 1;
*/
value: Uint8Array;
/**
* The public key of the signer in binary encoding as per the scheme.
*
* @generated from protobuf field: bytes signer = 2;
*/
signer: Uint8Array;
/**
* The name of the signature scheme (sr25519, secp256k1, ed25519).
* Default and recommended value: "" or "sr25519".
*
* @generated from protobuf field: string scheme = 3;
*/
scheme: string;
/**
* The ID of the hashing algorithm as per multiformats/multihash.
* Default and recommended value: 0 or 0xb220, meaning blake2b-256.
*
* @generated from protobuf field: uint64 multiHashType = 4;
*/
multiHashType: bigint;
/**
* The timestamp in UNIX milliseconds.
*
* @generated from protobuf field: uint64 timestamp = 5;
*/
timestamp: bigint;
}
// @generated message type with reflection information, may provide speed optimized methods
class Signature$Type extends MessageType {
constructor() {
super("pb.Signature", [
{ no: 1, name: "value", kind: "scalar", T: 12 /*ScalarType.BYTES*/ },
{ no: 2, name: "signer", kind: "scalar", T: 12 /*ScalarType.BYTES*/ },
{ no: 3, name: "scheme", kind: "scalar", T: 9 /*ScalarType.STRING*/ },
{ no: 4, name: "multiHashType", kind: "scalar", T: 4 /*ScalarType.UINT64*/, L: 0 /*LongType.BIGINT*/ },
{ no: 5, name: "timestamp", kind: "scalar", T: 4 /*ScalarType.UINT64*/, L: 0 /*LongType.BIGINT*/ }
]);
}
create(value?: PartialMessage): Signature {
const message = { value: new Uint8Array(0), signer: new Uint8Array(0), scheme: "", multiHashType: 0n, timestamp: 0n };
globalThis.Object.defineProperty(message, MESSAGE_TYPE, { enumerable: false, value: this });
if (value !== undefined)
reflectionMergePartial(this, message, value);
return message;
}
internalBinaryRead(reader: IBinaryReader, length: number, options: BinaryReadOptions, target?: Signature): Signature {
let message = target ?? this.create(), end = reader.pos + length;
while (reader.pos < end) {
let [fieldNo, wireType] = reader.tag();
switch (fieldNo) {
case /* bytes value */ 1:
message.value = reader.bytes();
break;
case /* bytes signer */ 2:
message.signer = reader.bytes();
break;
case /* string scheme */ 3:
message.scheme = reader.string();
break;
case /* uint64 multiHashType */ 4:
message.multiHashType = reader.uint64().toBigInt();
break;
case /* uint64 timestamp */ 5:
message.timestamp = reader.uint64().toBigInt();
break;
default:
let u = options.readUnknownField;
if (u === "throw")
throw new globalThis.Error(`Unknown field ${fieldNo} (wire type ${wireType}) for ${this.typeName}`);
let d = reader.skip(wireType);
if (u !== false)
(u === true ? UnknownFieldHandler.onRead : u)(this.typeName, message, fieldNo, wireType, d);
}
}
return message;
}
internalBinaryWrite(message: Signature, writer: IBinaryWriter, options: BinaryWriteOptions): IBinaryWriter {
/* bytes value = 1; */
if (message.value.length)
writer.tag(1, WireType.LengthDelimited).bytes(message.value);
/* bytes signer = 2; */
if (message.signer.length)
writer.tag(2, WireType.LengthDelimited).bytes(message.signer);
/* string scheme = 3; */
if (message.scheme !== "")
writer.tag(3, WireType.LengthDelimited).string(message.scheme);
/* uint64 multiHashType = 4; */
if (message.multiHashType !== 0n)
writer.tag(4, WireType.Varint).uint64(message.multiHashType);
/* uint64 timestamp = 5; */
if (message.timestamp !== 0n)
writer.tag(5, WireType.Varint).uint64(message.timestamp);
let u = options.writeUnknownFields;
if (u !== false)
(u == true ? UnknownFieldHandler.onWrite : u)(this.typeName, message, writer);
return writer;
}
}
/**
* @generated MessageType for protobuf message pb.Signature
*/
export const Signature = new Signature$Type();