import { ValidateASN1 } from '../utils/asn1'; import type { ASN1AnyJS } from '../utils/asn1'; import type { DeepMutable } from '../utils/helper'; import type { GenericAccount, IdentifierAddress, IdentifierKeyAlgorithm, TokenAddress, TokenPublicKeyString } from '../account'; import Account, { AccountKeyAlgorithm } from '../account'; import type { AcceptedPermissionTypes } from '../permissions'; import { Permissions } from '../permissions'; import type { ToJSONSerializable } from '../utils/conversion'; import Block, { AdjustMethod } from '.'; import { Certificate, CertificateBundle, type CertificateBundleJSONOutput, CertificateHash } from '../utils/certificate'; import type { MultisigConfig } from '../ledger/types'; /** * All supported operations */ export declare enum OperationType { SEND = 0, SET_REP = 1, SET_INFO = 2, MODIFY_PERMISSIONS = 3, CREATE_IDENTIFIER = 4, TOKEN_ADMIN_SUPPLY = 5, TOKEN_ADMIN_MODIFY_BALANCE = 6, RECEIVE = 7, MANAGE_CERTIFICATE = 8 } export type BlockOperationTypes = keyof typeof OperationType; declare const ModifyPermissionsPrincipalContextSpecificTagValues: { readonly CERTIFICATE: 1; }; export type ModifyPermissionsPrincipalContextSpecificTag = keyof typeof ModifyPermissionsPrincipalContextSpecificTagValues; /** * Schema for each operation as well as names of each field within the block operations */ declare const BlockOperationASN1SchemaBase: { readonly SEND: [{ readonly name: "to"; readonly schema: typeof ValidateASN1.IsOctetString; }, { readonly name: "amount"; readonly schema: typeof ValidateASN1.IsInteger; }, { readonly name: "token"; readonly schema: typeof ValidateASN1.IsOctetString; }, { readonly name: "external"; readonly schema: { readonly optional: { readonly type: "string"; readonly kind: "utf8"; }; }; }]; readonly RECEIVE: [{ readonly name: "amount"; readonly schema: typeof ValidateASN1.IsInteger; }, { readonly name: "token"; readonly schema: typeof ValidateASN1.IsOctetString; }, { readonly name: "from"; readonly schema: typeof ValidateASN1.IsOctetString; }, { readonly name: "exact"; readonly schema: typeof ValidateASN1.IsBoolean; }, { readonly name: "forward"; readonly schema: { readonly optional: typeof ValidateASN1.IsOctetString; }; }]; readonly SET_REP: [{ readonly name: "to"; readonly schema: typeof ValidateASN1.IsOctetString; }]; readonly SET_INFO: [{ readonly name: "name"; readonly schema: { readonly type: "string"; readonly kind: "utf8"; }; }, { readonly name: "description"; readonly schema: { readonly type: "string"; readonly kind: "utf8"; }; }, { readonly name: "metadata"; readonly schema: { readonly type: "string"; readonly kind: "utf8"; }; }, { readonly encode: (data: Permissions | undefined) => bigint[] | undefined; readonly decode: (data: ASN1AnyJS) => Permissions | undefined; readonly name: "defaultPermission"; readonly schema: { readonly optional: readonly [typeof ValidateASN1.IsInteger, typeof ValidateASN1.IsInteger]; }; }]; readonly MODIFY_PERMISSIONS: [{ readonly name: "principal"; readonly schema: { readonly choice: [typeof ValidateASN1.IsOctetString, { readonly type: "context"; readonly kind: "explicit"; readonly value: 1; readonly contains: readonly [typeof ValidateASN1.IsOctetString, typeof ValidateASN1.IsOctetString]; }]; }; readonly encode: (data: ModifyPermissionsPrincipal) => Buffer | { type: "context"; kind: "explicit"; value: 1; contains: Buffer[]; }; readonly decode: (data: ASN1AnyJS) => GenericAccount | { usingCertificate: true; certificateHash: CertificateHash; certificateAccount: GenericAccount; }; }, { readonly name: "method"; readonly schema: typeof ValidateASN1.IsInteger; }, { readonly encode: (data: Permissions | null) => bigint[] | null; readonly decode: (data: ASN1AnyJS) => Permissions | null; readonly name: "permissions"; readonly schema: { readonly choice: [typeof ValidateASN1.IsNull, readonly [typeof ValidateASN1.IsInteger, typeof ValidateASN1.IsInteger]]; }; }, { readonly name: "target"; readonly schema: { readonly optional: typeof ValidateASN1.IsOctetString; }; }]; readonly CREATE_IDENTIFIER: [{ readonly name: "identifier"; readonly schema: typeof ValidateASN1.IsOctetString; }, { readonly name: "createArguments"; readonly schema: { readonly optional: { readonly choice: [{ readonly type: "context"; readonly kind: "explicit"; readonly value: 7; readonly contains: readonly [{ readonly sequenceOf: typeof ValidateASN1.IsOctetString; }, typeof ValidateASN1.IsInteger]; }]; }; }; readonly encode: (data: MultiSigIdentifierCreateArguments | undefined) => ASN1AnyJS; readonly decode: (data: ASN1AnyJS) => IdentifierCreateArguments | undefined; }]; readonly TOKEN_ADMIN_SUPPLY: [{ readonly name: "amount"; readonly schema: typeof ValidateASN1.IsInteger; }, { readonly name: "method"; readonly schema: typeof ValidateASN1.IsInteger; }]; readonly TOKEN_ADMIN_MODIFY_BALANCE: [{ readonly name: "token"; readonly schema: typeof ValidateASN1.IsOctetString; }, { readonly name: "amount"; readonly schema: typeof ValidateASN1.IsInteger; }, { readonly name: "method"; readonly schema: typeof ValidateASN1.IsInteger; }]; readonly MANAGE_CERTIFICATE: [{ readonly name: "method"; readonly schema: typeof ValidateASN1.IsInteger; }, { readonly name: "certificateOrHash"; readonly schema: typeof ValidateASN1.IsOctetString; readonly encode: (data: Certificate | CertificateHash) => Buffer; readonly decode: (data: ASN1AnyJS) => Certificate | CertificateHash; }, { readonly name: "intermediateCertificates"; readonly schema: { readonly optional: { readonly choice: [typeof ValidateASN1.IsNull, { readonly sequenceOf: typeof ValidateASN1.IsOctetString; }]; }; }; readonly decode: (data: ASN1AnyJS) => CertificateBundle | null; readonly encode: (data: CertificateBundle | null | undefined) => Buffer[] | null; }]; }; type ExtractSchemaFromBase = { [K in keyof T]: T[K]['schema']; }; /** * Schema for each operation */ export declare const BlockOperationASN1Schema: { [T in BlockOperationTypes]: { type: "context"; kind: "explicit"; value: (typeof OperationType)[T]; contains: DeepMutable>; }; }; export type BlockOperationASN1SchemaType = typeof BlockOperationASN1Schema[T]; export interface BlockJSONOperation { type: OperationType; } interface BlockOperationValidateContext { block: Pick; operationIndex: number; } declare class BlockOperation { static isInstance: (obj: any, strict?: boolean) => obj is BlockOperation; validate(_ignored_context: BlockOperationValidateContext): void; protected computeTo(to: string | GenericAccount, isIdentifier: false): Account; protected computeTo(to: string | GenericAccount, isIdentifier: true): IdentifierAddress; protected computeTo(to: string | GenericAccount, isIdentifier?: undefined): GenericAccount; protected computeAmount(amount: string | bigint): bigint; } export interface BlockJSONOperationSEND extends BlockJSONOperation { type: OperationType.SEND; to: string | GenericAccount; amount: string | bigint; token: TokenPublicKeyString | TokenAddress; external?: string; } declare class BlockOperationSEND extends BlockOperation implements BlockJSONOperationSEND { #private; static isInstance: (obj: any, strict?: boolean) => obj is BlockOperationSEND; type: OperationType.SEND; external: string | undefined; constructor(input: BlockJSONOperationSEND); set to(to: string | GenericAccount); get to(): GenericAccount; set token(token: TokenPublicKeyString | TokenAddress); get token(): TokenAddress; set amount(amount: string | bigint); get amount(): bigint; validate(context: BlockOperationValidateContext): void; toJSON(): ToJSONSerializable; } export interface BlockJSONOperationRECEIVE extends BlockJSONOperation { type: OperationType.RECEIVE; amount: string | bigint; token: TokenPublicKeyString | TokenAddress; from: string | GenericAccount; forward?: string | GenericAccount; exact?: boolean; } declare class BlockOperationRECEIVE extends BlockOperation implements BlockJSONOperationRECEIVE { #private; static isInstance: (obj: any, strict?: boolean) => obj is BlockOperationRECEIVE; type: OperationType.RECEIVE; constructor(input: BlockJSONOperationRECEIVE); set from(from: string | GenericAccount); get from(): GenericAccount; set forward(forward: undefined | string | GenericAccount); get forward(): GenericAccount | undefined; set exact(exact: boolean | undefined); get exact(): boolean; set token(token: TokenPublicKeyString | TokenAddress); get token(): TokenAddress; set amount(amount: string | bigint); get amount(): bigint; validate(context: BlockOperationValidateContext): void; toJSON(): ToJSONSerializable; } export interface BlockJSONOperationTOKEN_ADMIN_MODIFY_BALANCE extends BlockJSONOperation { type: OperationType.TOKEN_ADMIN_MODIFY_BALANCE; token: TokenPublicKeyString | TokenAddress; amount: string | bigint; method: AdjustMethod; } declare class BlockOperationTOKEN_ADMIN_MODIFY_BALANCE extends BlockOperation implements BlockJSONOperationTOKEN_ADMIN_MODIFY_BALANCE { #private; static isInstance: (obj: any, strict?: boolean) => obj is BlockOperationTOKEN_ADMIN_MODIFY_BALANCE; type: OperationType.TOKEN_ADMIN_MODIFY_BALANCE; constructor(input: BlockJSONOperationTOKEN_ADMIN_MODIFY_BALANCE); set token(token: TokenPublicKeyString | TokenAddress); get token(): TokenAddress; set method(newMethod: AdjustMethod); get method(): AdjustMethod; set amount(amount: string | bigint); get amount(): bigint; validate(context: BlockOperationValidateContext): void; toJSON(): ToJSONSerializable; } /** * SetRep operation */ export interface BlockJSONOperationSET_REP extends BlockJSONOperation { type: OperationType.SET_REP; to: string | GenericAccount; } declare class BlockOperationSET_REP extends BlockOperation implements BlockJSONOperationSET_REP { #private; static isInstance: (obj: any, strict?: boolean) => obj is BlockOperationSET_REP; type: OperationType.SET_REP; constructor(input: BlockJSONOperationSET_REP); set to(to: string | Account); get to(): Account; validate(context: BlockOperationValidateContext): void; toJSON(): ToJSONSerializable; } /** * TokenCreate Operation */ interface BaseIdentifierCreateArguments { type: KeyType; } interface MultiSigIdentifierCreateArguments extends BaseIdentifierCreateArguments, MultisigConfig { } export type IdentifierCreateArguments = MultiSigIdentifierCreateArguments; export interface BlockJSONOperationCREATE_IDENTIFIER extends BlockJSONOperation { type: OperationType.CREATE_IDENTIFIER; identifier: IdentifierAddress | string; createArguments?: ToJSONSerializable | IdentifierCreateArguments; } declare class BlockOperationCREATE_IDENTIFIER extends BlockOperation implements BlockJSONOperationCREATE_IDENTIFIER { #private; static isInstance: (obj: any, strict?: boolean) => obj is BlockOperationCREATE_IDENTIFIER; type: OperationType.CREATE_IDENTIFIER; constructor(input: BlockJSONOperationCREATE_IDENTIFIER); set identifier(identifier: string | IdentifierAddress); get identifier(): IdentifierAddress; set createArguments(input: IdentifierCreateArguments | ToJSONSerializable | undefined); get createArguments(): IdentifierCreateArguments | undefined; validate(context: BlockOperationValidateContext): void; toJSON(): ToJSONSerializable; } /** * SetInfo operation */ export interface BlockJSONOperationSET_INFO extends BlockJSONOperation { type: OperationType.SET_INFO; name: string; description: string; metadata: string; defaultPermission?: AcceptedPermissionTypes; } declare class BlockOperationSET_INFO extends BlockOperation implements BlockJSONOperationSET_INFO { #private; static isInstance: (obj: any, strict?: boolean) => obj is BlockOperationSET_INFO; type: OperationType.SET_INFO; constructor(input: BlockJSONOperationSET_INFO); set name(name: string); get name(): string; set description(description: string); get description(): string; set metadata(metadata: string); get metadata(): string; set defaultPermission(newPerms: Permissions | undefined); get defaultPermission(): Permissions | undefined; validate(context: BlockOperationValidateContext): void; toJSON(): ToJSONSerializable; } export type ModifyPermissionsPrincipal = GenericAccount | { usingCertificate: true; certificateHash: CertificateHash; certificateAccount: GenericAccount; }; type ModifyPermissionsPrincipalInput = GenericAccount | string | { usingCertificate: true; certificateHash: CertificateHash | ConstructorParameters[0]; certificateAccount: GenericAccount | string; }; /** * Set Permissions Operation */ export interface BlockJSONOperationMODIFY_PERMISSIONS extends BlockJSONOperation { type: OperationType.MODIFY_PERMISSIONS; principal: ModifyPermissionsPrincipalInput; method: AdjustMethod; permissions: AcceptedPermissionTypes | null; target?: string | GenericAccount; } declare class BlockOperationMODIFY_PERMISSIONS extends BlockOperation implements BlockJSONOperationMODIFY_PERMISSIONS { #private; static isInstance: (obj: any, strict?: boolean) => obj is BlockOperationMODIFY_PERMISSIONS; type: OperationType.MODIFY_PERMISSIONS; constructor(input: BlockJSONOperationMODIFY_PERMISSIONS); set principal(principal: string | GenericAccount); get principal(): ModifyPermissionsPrincipal; set permissions(newPerms: Permissions | null); get permissions(): Permissions | null; set target(token: string | GenericAccount | undefined); get target(): GenericAccount | undefined; set method(method: AdjustMethod); get method(): AdjustMethod; validate(context: BlockOperationValidateContext): void; toJSON(): ToJSONSerializable; } /** * Token Supply operation */ export interface BlockJSONOperationTOKEN_ADMIN_SUPPLY extends BlockJSONOperation { type: OperationType.TOKEN_ADMIN_SUPPLY; amount: bigint | string; method: AdjustMethod.ADD | AdjustMethod.SUBTRACT; } declare class BlockOperationTOKEN_ADMIN_SUPPLY extends BlockOperation implements BlockJSONOperationTOKEN_ADMIN_SUPPLY { #private; static isInstance: (obj: any, strict?: boolean) => obj is BlockOperationTOKEN_ADMIN_SUPPLY; type: OperationType.TOKEN_ADMIN_SUPPLY; constructor(input: BlockJSONOperationTOKEN_ADMIN_SUPPLY); set amount(amount: string | bigint); get amount(): bigint; set method(shouldAdd: BlockJSONOperationTOKEN_ADMIN_SUPPLY['method']); get method(): BlockJSONOperationTOKEN_ADMIN_SUPPLY['method']; validate(context: BlockOperationValidateContext): void; toJSON(): ToJSONSerializable; } /** * X.509 Certificate operations */ export interface BlockJSONOperationMANAGE_CERTIFICATE extends BlockJSONOperation { type: OperationType.MANAGE_CERTIFICATE; certificateOrHash: string | CertificateHash | ConstructorParameters[0]; intermediateCertificates?: string | CertificateBundle | CertificateBundleJSONOutput | null; method: Exclude; } declare class BlockOperationMANAGE_CERTIFICATE extends BlockOperation implements BlockJSONOperationMANAGE_CERTIFICATE { #private; type: OperationType.MANAGE_CERTIFICATE; constructor(input: BlockJSONOperationMANAGE_CERTIFICATE); get intermediateCertificates(): CertificateBundle | null | undefined; set intermediateCertificates(bundle: ConstructorParameters[0] | null | undefined); get certificateOrHash(): Certificate | CertificateHash; set certificateOrHash(certificate: string | Certificate | CertificateHash | Buffer); set method(shouldAdd: Exclude); get method(): Exclude; validate(context: BlockOperationValidateContext): void; toJSON(): ToJSONSerializable; } /** * Aggregate set of operations */ export declare const Operation: { SEND: typeof BlockOperationSEND; SET_REP: typeof BlockOperationSET_REP; SET_INFO: typeof BlockOperationSET_INFO; MODIFY_PERMISSIONS: typeof BlockOperationMODIFY_PERMISSIONS; CREATE_IDENTIFIER: typeof BlockOperationCREATE_IDENTIFIER; TOKEN_ADMIN_SUPPLY: typeof BlockOperationTOKEN_ADMIN_SUPPLY; TOKEN_ADMIN_MODIFY_BALANCE: typeof BlockOperationTOKEN_ADMIN_MODIFY_BALANCE; RECEIVE: typeof BlockOperationRECEIVE; MANAGE_CERTIFICATE: typeof BlockOperationMANAGE_CERTIFICATE; }; export type { BlockOperationSEND, BlockOperationSET_REP, BlockOperationSET_INFO, BlockOperationMODIFY_PERMISSIONS, BlockOperationCREATE_IDENTIFIER, BlockOperationTOKEN_ADMIN_SUPPLY, BlockOperationTOKEN_ADMIN_MODIFY_BALANCE, BlockOperationRECEIVE, BlockOperationMANAGE_CERTIFICATE }; export type BlockOperations = InstanceType; export type BlockJSONOperations = ConstructorParameters[0]; export declare function createBlockOperation(input: BlockJSONOperations | ToJSONSerializable): BlockOperationSEND | BlockOperationSET_REP | BlockOperationSET_INFO | BlockOperationMODIFY_PERMISSIONS | BlockOperationCREATE_IDENTIFIER | BlockOperationTOKEN_ADMIN_SUPPLY | BlockOperationTOKEN_ADMIN_MODIFY_BALANCE | BlockOperationRECEIVE | BlockOperationMANAGE_CERTIFICATE; export declare function isBlockOperation(input: any): input is BlockOperations; /** * Export the "operations" mapping as something compatible with being * serialized to JSON */ export declare function ExportOperationsJSON(operations: BlockOperations[]): ToJSONSerializable[]; export declare function ImportOperationsJSON(operations: (BlockOperations | BlockJSONOperations)[]): BlockOperations[]; export declare function ExportBlockOperations(operations: BlockOperations[]): ((Omit & { contains: [bigint, bigint]; value: OperationType.TOKEN_ADMIN_SUPPLY; kind: "explicit"; }) | (Omit & { contains: [Buffer, bigint, bigint]; value: OperationType.TOKEN_ADMIN_MODIFY_BALANCE; kind: "explicit"; }) | (Omit & { contains: [bigint, Buffer, Buffer[] | null | undefined]; value: OperationType.MANAGE_CERTIFICATE; kind: "explicit"; }) | (Omit & { contains: [Buffer, bigint, Buffer, (Omit & { kind: "utf8"; }) | undefined]; value: OperationType.SEND; kind: "explicit"; }) | (Omit & { contains: [Buffer]; value: OperationType.SET_REP; kind: "explicit"; }) | (Omit & { contains: [Omit & { kind: "utf8"; }, Omit & { kind: "utf8"; }, Omit & { kind: "utf8"; }, [bigint, bigint] | undefined]; value: OperationType.SET_INFO; kind: "explicit"; }) | (Omit & { contains: [Buffer | (Omit & { contains: [Buffer, Buffer]; value: 1; kind: "explicit"; }), bigint, [bigint, bigint] | null, Buffer | undefined]; value: OperationType.MODIFY_PERMISSIONS; kind: "explicit"; }) | (Omit & { contains: [Buffer, (Omit & { contains: [Buffer[], bigint]; value: 7; kind: "explicit"; }) | undefined]; value: OperationType.CREATE_IDENTIFIER; kind: "explicit"; }) | (Omit & { contains: [bigint, Buffer, Buffer, boolean, Buffer | undefined]; value: OperationType.RECEIVE; kind: "explicit"; }))[]; export declare function ImportOperationsASN1(input: unknown[], network: bigint): BlockOperations[];