diff --git a/bindings/nodejs/lib/client/client.ts b/bindings/nodejs/lib/client/client.ts index 7a16ac7e37..f158874354 100644 --- a/bindings/nodejs/lib/client/client.ts +++ b/bindings/nodejs/lib/client/client.ts @@ -1,7 +1,9 @@ // Copyright 2021-2023 IOTA Stiftung // SPDX-License-Identifier: Apache-2.0 +import { plainToInstance } from 'class-transformer'; import { ClientMethodHandler } from './client-method-handler'; +import { Response } from '../types'; import { ClientOptions, Node, @@ -18,7 +20,6 @@ import { NftOutputQueryParameters, OutputQueryParameters, } from '../types/client'; -import type { NodeInfoResponse } from '../types/client/nodeInfo'; import { AccountOutput, BasicOutput, @@ -42,39 +43,35 @@ import { EpochIndex, Address, } from '../types/block'; +import type { NodeInfoResponse } from '../types/client/nodeInfo'; import { - BlockMetadataResponse, - InfoResponse, UTXOInput, - Response, OutputId, ProtocolParameters, u64, TransactionId, Bech32Address, - BlockWithMetadataResponse, - TransactionMetadataResponse, } from '../types'; import { - OutputResponse, - OutputsResponse, - CongestionResponse, - UtxoChangesResponse, - UtxoChangesFullResponse, - CommitteeResponse, + BlockMetadataResponse, + BlockWithMetadataResponse, + InfoResponse, IssuanceBlockHeaderResponse, + CommitteeResponse, + CongestionResponse, + ManaRewardsResponse, + NetworkMetricsResponse, OutputMetadataResponse, + OutputResponse, + OutputsResponse, OutputWithMetadataResponse, - NetworkMetricsResponse, -} from '../types/models/api'; -import { RoutesResponse } from '../types/models/api/routes-response'; - -import { plainToInstance } from 'class-transformer'; -import { ManaRewardsResponse } from '../types/models/api/mana-rewards-response'; -import { + RoutesResponse, + TransactionMetadataResponse, + UtxoChangesFullResponse, + UtxoChangesResponse, ValidatorResponse, ValidatorsResponse, -} from '../types/models/api/validators-response'; +} from '../types/models/api'; /** The Client to interact with nodes. */ export class Client { diff --git a/bindings/nodejs/lib/types/client/client-options.ts b/bindings/nodejs/lib/types/client/client-options.ts index 43b524e83e..47b26d9280 100644 --- a/bindings/nodejs/lib/types/client/client-options.ts +++ b/bindings/nodejs/lib/types/client/client-options.ts @@ -1,7 +1,7 @@ // Copyright 2021-2024 IOTA Stiftung // SPDX-License-Identifier: Apache-2.0 -import { ProtocolParameters } from '../models/api/info/node-info-protocol'; +import { ProtocolParameters } from '../models/api'; import type { MqttBrokerOptions, Node } from './network'; /** Options for the client builder */ diff --git a/bindings/nodejs/lib/types/client/nodeInfo.ts b/bindings/nodejs/lib/types/client/nodeInfo.ts index 5fa0ebeede..c51b8a1709 100644 --- a/bindings/nodejs/lib/types/client/nodeInfo.ts +++ b/bindings/nodejs/lib/types/client/nodeInfo.ts @@ -1,7 +1,7 @@ // Copyright 2021-2023 IOTA Stiftung // SPDX-License-Identifier: Apache-2.0 -import { InfoResponse } from '../models/api/info'; +import { InfoResponse } from '../models/api'; /** NodeInfo wrapper which contains the node info and the url from the node (useful when multiple nodes are used) */ export interface NodeInfoResponse { diff --git a/bindings/nodejs/lib/types/models/api/congestion-response.ts b/bindings/nodejs/lib/types/models/api/accounts.ts similarity index 100% rename from bindings/nodejs/lib/types/models/api/congestion-response.ts rename to bindings/nodejs/lib/types/models/api/accounts.ts diff --git a/bindings/nodejs/lib/types/models/api/block-response.ts b/bindings/nodejs/lib/types/models/api/block-response.ts deleted file mode 100644 index c90c32d30e..0000000000 --- a/bindings/nodejs/lib/types/models/api/block-response.ts +++ /dev/null @@ -1,33 +0,0 @@ -// Copyright 2023 IOTA Stiftung -// SPDX-License-Identifier: Apache-2.0 - -import { BlockState } from '../state'; -import { Block, BlockId } from '../../block'; - -/** - * Response from the metadata endpoint. - */ -export interface BlockMetadataResponse { - /** - * The block id. - */ - blockId: BlockId; - /** - * The block state. - */ - blockState: BlockState; -} - -/** - * Response from the full endpoint. - */ -export interface BlockWithMetadataResponse { - /** - * The block. - */ - block: Block; - /** - * The block metadata. - */ - metadata: BlockMetadataResponse; -} diff --git a/bindings/nodejs/lib/types/models/api/issuance-response.ts b/bindings/nodejs/lib/types/models/api/blocks.ts similarity index 61% rename from bindings/nodejs/lib/types/models/api/issuance-response.ts rename to bindings/nodejs/lib/types/models/api/blocks.ts index c45b59e607..ef41c033c0 100644 --- a/bindings/nodejs/lib/types/models/api/issuance-response.ts +++ b/bindings/nodejs/lib/types/models/api/blocks.ts @@ -1,7 +1,8 @@ // Copyright 2024 IOTA Stiftung // SPDX-License-Identifier: Apache-2.0 -import { BlockId, SlotCommitment, SlotIndex } from '../../block'; +import { BlockState } from '../state'; +import { Block, BlockId, SlotCommitment, SlotIndex } from '../../block'; import { NumericString } from '../../utils'; /** @@ -34,3 +35,31 @@ export interface IssuanceBlockHeaderResponse { */ shallowLikeParents?: BlockId[]; } + +/** + * Response from the metadata endpoint. + */ +export interface BlockMetadataResponse { + /** + * The block id. + */ + blockId: BlockId; + /** + * The block state. + */ + blockState: BlockState; +} + +/** + * Response from the full endpoint. + */ +export interface BlockWithMetadataResponse { + /** + * The block. + */ + block: Block; + /** + * The block metadata. + */ + metadata: BlockMetadataResponse; +} diff --git a/bindings/nodejs/lib/types/models/api/utxo-changes-response.ts b/bindings/nodejs/lib/types/models/api/commitments.ts similarity index 91% rename from bindings/nodejs/lib/types/models/api/utxo-changes-response.ts rename to bindings/nodejs/lib/types/models/api/commitments.ts index 6db602b7d8..639b03ba41 100644 --- a/bindings/nodejs/lib/types/models/api/utxo-changes-response.ts +++ b/bindings/nodejs/lib/types/models/api/commitments.ts @@ -1,10 +1,9 @@ // Copyright 2024 IOTA Stiftung // SPDX-License-Identifier: Apache-2.0 -import { OutputId } from '../../block/output'; -import { SlotCommitmentId } from '../../block'; -import { Output, OutputDiscriminator } from '../../block/output'; import { Type } from 'class-transformer'; +import { SlotCommitmentId } from '../../block'; +import { Output, OutputId, OutputDiscriminator } from '../../block/output'; /** * All UTXO changes that happened at a specific slot. diff --git a/bindings/nodejs/lib/types/models/api/committee-response.ts b/bindings/nodejs/lib/types/models/api/committee.ts similarity index 100% rename from bindings/nodejs/lib/types/models/api/committee-response.ts rename to bindings/nodejs/lib/types/models/api/committee.ts diff --git a/bindings/nodejs/lib/types/models/api/index.ts b/bindings/nodejs/lib/types/models/api/index.ts index 1b6b06102e..ce8948e30f 100644 --- a/bindings/nodejs/lib/types/models/api/index.ts +++ b/bindings/nodejs/lib/types/models/api/index.ts @@ -1,20 +1,12 @@ -// Copyright 2023 IOTA Stiftung +// Copyright 2024 IOTA Stiftung // SPDX-License-Identifier: Apache-2.0 -export * from './info'; +export * from './accounts'; +export * from './blocks'; +export * from './commitments'; +export * from './committee'; +export * from './node'; export * from './plugins'; -export * from './block-response'; -export * from './committee-response'; -export * from './congestion-response'; -export * from './issuance-response'; -export * from './mana-rewards-response'; -export * from './network-metrics'; -export * from './output-id-proof'; -export * from './output-metadata-response'; -export * from './output-response'; -export * from './response'; -export * from './routes-response'; -export * from './transaction-failure-reason'; -export * from './transaction-response'; -export * from './utxo-changes-response'; -export * from './validators-response'; +export * from './rewards'; +export * from './utxo'; +export * from './validators'; diff --git a/bindings/nodejs/lib/types/models/api/info/index.ts b/bindings/nodejs/lib/types/models/api/info/index.ts deleted file mode 100644 index 0a6f82288a..0000000000 --- a/bindings/nodejs/lib/types/models/api/info/index.ts +++ /dev/null @@ -1,7 +0,0 @@ -// Copyright 2023 IOTA Stiftung -// SPDX-License-Identifier: Apache-2.0 - -export * from './node-info'; -export * from './node-info-base-token'; -export * from './node-info-protocol'; -export * from './node-info-status'; diff --git a/bindings/nodejs/lib/types/models/api/info/node-info-base-token.ts b/bindings/nodejs/lib/types/models/api/info/node-info-base-token.ts deleted file mode 100644 index 640e6a444f..0000000000 --- a/bindings/nodejs/lib/types/models/api/info/node-info-base-token.ts +++ /dev/null @@ -1,32 +0,0 @@ -// Copyright 2023 IOTA Stiftung -// SPDX-License-Identifier: Apache-2.0 - -/** - * The base token info of the node. - */ -export interface BaseTokenResponse { - /** - * The base token name. - */ - name: string; - /** - * The base token ticker symbol. - */ - tickerSymbol: string; - /** - * The base token unit. - */ - unit: string; - /** - * The base token decimals. - */ - decimals: number; - /** - * The base token sub-unit. - */ - subunit?: string; - /** - * The use metric prefix flag. - */ - useMetricPrefix: boolean; -} diff --git a/bindings/nodejs/lib/types/models/api/info/node-info-status.ts b/bindings/nodejs/lib/types/models/api/info/node-info-status.ts deleted file mode 100644 index c9d36c88de..0000000000 --- a/bindings/nodejs/lib/types/models/api/info/node-info-status.ts +++ /dev/null @@ -1,50 +0,0 @@ -// Copyright 2023 IOTA Stiftung -// SPDX-License-Identifier: Apache-2.0 - -import { SlotIndex, EpochIndex } from '../../../block/slot'; - -/** - * Response from the /info endpoint. - */ -export interface StatusResponse { - /** - * Tells whether the node is healthy or not. - */ - isHealthy: boolean; - /** - * A notion of time that is anchored to the latest accepted block. - */ - acceptedTangleTime?: string; - /** - * The Accepted Tangle Time after it has advanced with the system clock. - */ - relativeAcceptedTangleTime?: string; - /** - * A notion of time that is anchored to the latest confirmed block. - */ - confirmedTangleTime?: string; - /** - * The Confirmed Tangle Time after it has advanced with the system clock. - */ - relativeConfirmedTangleTime?: string; - /** - * The latest slot that the node has committed to. - */ - latestCommitmentId: string; - /** - * The index of latest finalized slot. - */ - latestFinalizedSlot: SlotIndex; - /** - * The slot index of the latest accepted block. - */ - latestAcceptedBlockSlot?: SlotIndex; - /** - * The slot index of the latest confirmed block. - */ - latestConfirmedBlockSlot?: SlotIndex; - /** - * The index of the epoch before which the tangle history is pruned. - */ - pruningEpoch: EpochIndex; -} diff --git a/bindings/nodejs/lib/types/models/api/info/node-info.ts b/bindings/nodejs/lib/types/models/api/info/node-info.ts deleted file mode 100644 index fbe4c1ecc3..0000000000 --- a/bindings/nodejs/lib/types/models/api/info/node-info.ts +++ /dev/null @@ -1,31 +0,0 @@ -// Copyright 2023 IOTA Stiftung -// SPDX-License-Identifier: Apache-2.0 - -import type { BaseTokenResponse } from './node-info-base-token'; -import type { ProtocolParametersResponse } from './node-info-protocol'; -import type { StatusResponse } from './node-info-status'; -/** - * Response from the /info endpoint. - */ -export interface InfoResponse { - /** - * The name of the node. - */ - name: string; - /** - * The semantic version of the node. - */ - version: string; - /** - * The status of the node. - */ - status: StatusResponse; - /** - * The protocol parameters. - */ - protocolParameters: ProtocolParametersResponse[]; - /** - * The base token info of the node. - */ - baseToken: BaseTokenResponse; -} diff --git a/bindings/nodejs/lib/types/models/api/network-metrics.ts b/bindings/nodejs/lib/types/models/api/network-metrics.ts deleted file mode 100644 index ab783806f8..0000000000 --- a/bindings/nodejs/lib/types/models/api/network-metrics.ts +++ /dev/null @@ -1,20 +0,0 @@ -// Copyright 2024 IOTA Stiftung -// SPDX-License-Identifier: Apache-2.0 - -/** - * Metrics information about the network. - */ -export interface NetworkMetricsResponse { - /** - * The current rate of new blocks per second. - */ - blocksPerSecond: string; - /** - * The current rate of confirmed blocks per second. - */ - confirmedBlocksPerSecond: string; - /** - * The ratio of confirmed blocks to new blocks of the last confirmed slot. - */ - confirmationRate: string; -} diff --git a/bindings/nodejs/lib/types/models/api/info/node-info-protocol.ts b/bindings/nodejs/lib/types/models/api/node.ts similarity index 72% rename from bindings/nodejs/lib/types/models/api/info/node-info-protocol.ts rename to bindings/nodejs/lib/types/models/api/node.ts index 117c37c651..f9fc055530 100644 --- a/bindings/nodejs/lib/types/models/api/info/node-info-protocol.ts +++ b/bindings/nodejs/lib/types/models/api/node.ts @@ -1,14 +1,60 @@ -// Copyright 2023 IOTA Stiftung +// Copyright 2024 IOTA Stiftung // SPDX-License-Identifier: Apache-2.0 -import type { StorageScoreParameters } from '../../storage-score'; -import { EpochIndex } from '../../../block/slot'; -import { NumericString } from '../../../utils'; +import type { StorageScoreParameters } from '../storage-score'; +import { SlotIndex, EpochIndex } from '../../block/slot'; +import { NumericString } from '../../utils'; + +/** + * Response from the /info endpoint. + */ +export interface StatusResponse { + /** + * Tells whether the node is healthy or not. + */ + isHealthy: boolean; + /** + * A notion of time that is anchored to the latest accepted block. + */ + acceptedTangleTime?: string; + /** + * The Accepted Tangle Time after it has advanced with the system clock. + */ + relativeAcceptedTangleTime?: string; + /** + * A notion of time that is anchored to the latest confirmed block. + */ + confirmedTangleTime?: string; + /** + * The Confirmed Tangle Time after it has advanced with the system clock. + */ + relativeConfirmedTangleTime?: string; + /** + * The latest slot that the node has committed to. + */ + latestCommitmentId: string; + /** + * The index of latest finalized slot. + */ + latestFinalizedSlot: SlotIndex; + /** + * The slot index of the latest accepted block. + */ + latestAcceptedBlockSlot?: SlotIndex; + /** + * The slot index of the latest confirmed block. + */ + latestConfirmedBlockSlot?: SlotIndex; + /** + * The index of the epoch before which the tangle history is pruned. + */ + pruningEpoch: EpochIndex; +} /** * The Protocol Parameters response. */ -interface ProtocolParametersResponse { +export interface ProtocolParametersResponse { /** * The protocol parameters. */ @@ -22,7 +68,7 @@ interface ProtocolParametersResponse { /** * The Protocol Parameters. */ -interface ProtocolParameters { +export interface ProtocolParameters { /** * Set to value 0 to denote a IOTA 2.0 protocol parameter. */ @@ -129,7 +175,7 @@ interface ProtocolParameters { /** * Rewards Parameters defines the parameters that are used to calculate Mana rewards. */ -interface RewardsParameters { +export interface RewardsParameters { /** * Profit Margin Exponent is used for shift operation for calculation of profit margin. */ @@ -164,7 +210,7 @@ interface RewardsParameters { /** * Work Score Parameters lists the work score of each type, it is used to denote the computation costs of processing an object. */ -interface WorkScoreParameters { +export interface WorkScoreParameters { /** * DataByte accounts for the network traffic per kibibyte. */ @@ -210,7 +256,7 @@ interface WorkScoreParameters { /** * ManaParameters defines the parameters used by mana calculation. */ -interface ManaParameters { +export interface ManaParameters { /** * The number of bits used to represent Mana. */ @@ -248,7 +294,7 @@ interface ManaParameters { /** * Congestion Control Parameters defines the parameters used to calculate the Reference Mana Cost (RMC). */ -interface CongestionControlParameters { +export interface CongestionControlParameters { /** * The minimum value of the reference Mana cost. */ @@ -286,7 +332,7 @@ interface CongestionControlParameters { /** * The version signaling parameters. */ -interface VersionSignalingParameters { +export interface VersionSignalingParameters { /** * The size of the window in epochs to find which version of protocol parameters was most signaled, from currentEpoch - windowSize to currentEpoch. */ @@ -301,13 +347,86 @@ interface VersionSignalingParameters { activationOffset: number; } -export { - ProtocolParametersResponse, - ProtocolParameters, - RewardsParameters, - WorkScoreParameters, - StorageScoreParameters, - ManaParameters, - VersionSignalingParameters, - CongestionControlParameters, -}; +/** + * The base token info of the node. + */ +export interface BaseTokenResponse { + /** + * The base token name. + */ + name: string; + /** + * The base token ticker symbol. + */ + tickerSymbol: string; + /** + * The base token unit. + */ + unit: string; + /** + * The base token decimals. + */ + decimals: number; + /** + * The base token sub-unit. + */ + subunit?: string; + /** + * The use metric prefix flag. + */ + useMetricPrefix: boolean; +} + +/** + * Response from the /info endpoint. + */ +export interface InfoResponse { + /** + * The name of the node. + */ + name: string; + /** + * The semantic version of the node. + */ + version: string; + /** + * The status of the node. + */ + status: StatusResponse; + /** + * The protocol parameters. + */ + protocolParameters: ProtocolParametersResponse[]; + /** + * The base token info of the node. + */ + baseToken: BaseTokenResponse; +} + +/** + * Metrics information about the network. + */ +export interface NetworkMetricsResponse { + /** + * The current rate of new blocks per second. + */ + blocksPerSecond: string; + /** + * The current rate of confirmed blocks per second. + */ + confirmedBlocksPerSecond: string; + /** + * The ratio of confirmed blocks to new blocks of the last confirmed slot. + */ + confirmationRate: string; +} + +/** + * Response from the /routes endpoint. + */ +export interface RoutesResponse { + /** + * The routes the node exposes. + */ + routes: string[]; +} diff --git a/bindings/nodejs/lib/types/models/api/output-id-proof.ts b/bindings/nodejs/lib/types/models/api/output-id-proof.ts deleted file mode 100644 index fedab6ba4c..0000000000 --- a/bindings/nodejs/lib/types/models/api/output-id-proof.ts +++ /dev/null @@ -1,120 +0,0 @@ -// Copyright 2024 IOTA Stiftung -// SPDX-License-Identifier: Apache-2.0 - -// Temp solution for not double parsing JSON -import { plainToInstance } from 'class-transformer'; -import { SlotIndex } from '../../block'; -import { HexEncodedString } from '../../utils'; - -/** - * OutputCommitmentProof types. - */ -export enum OutputCommitmentProofType { - /** Denotes a HashableNode. */ - HashableNode = 0, - /** Denotes a LeafHash. */ - LeafHash = 1, - /** Denotes a ValueHash. */ - ValueHash = 2, -} - -export abstract class OutputCommitmentProof { - readonly type: OutputCommitmentProofType; - - /** - * @param type The type of OutputCommitmentProof. - */ - constructor(type: OutputCommitmentProofType) { - this.type = type; - } - - /** - * Parse an OutputCommitmentProof from a plain JSON object. - */ - public static parse(data: any): OutputCommitmentProof { - if (data.type == OutputCommitmentProofType.HashableNode) { - return plainToInstance(HashableNode, data) as any as HashableNode; - } else if (data.type == OutputCommitmentProofType.LeafHash) { - return plainToInstance(LeafHash, data) as any as LeafHash; - } else if (data.type == OutputCommitmentProofType.ValueHash) { - return plainToInstance(ValueHash, data) as any as ValueHash; - } - throw new Error('Invalid JSON'); - } -} - -/** - * Contains the hashes of the left and right children of a node in the OutputCommitmentProof tree. - */ -export class HashableNode extends OutputCommitmentProof { - readonly l: OutputCommitmentProof; - readonly r: OutputCommitmentProof; - - /** - * @param l Output commitment proof of the left subtree. - * @param r Output commitment proof of the right subtree. - */ - constructor(l: OutputCommitmentProof, r: OutputCommitmentProof) { - super(OutputCommitmentProofType.HashableNode); - this.l = l; - this.r = r; - } -} - -/** - * Contains the hash of a leaf in the OutputCommitmentProof tree. - */ -export class LeafHash extends OutputCommitmentProof { - readonly hash: HexEncodedString; - - /** - * @param hash The hash of the leaf. - */ - constructor(hash: HexEncodedString) { - super(OutputCommitmentProofType.LeafHash); - this.hash = hash; - } -} - -/** - * Contains the hash of the value for which the OutputCommitmentProof is being computed. - */ -export class ValueHash extends OutputCommitmentProof { - readonly hash: HexEncodedString; - - /** - * @param hash The hash of the value. - */ - constructor(hash: HexEncodedString) { - super(OutputCommitmentProofType.ValueHash); - this.hash = hash; - } -} - -/** - * The proof of the output identifier. - */ -export class OutputIdProof { - readonly slot: SlotIndex; - readonly outputIndex: number; - readonly transactionCommitment: HexEncodedString; - readonly outputCommitmentProof: OutputCommitmentProof; - - /** - * @param slot The slot index of the output. - * @param outputIndex The index of the output within the corresponding transaction. - * @param transactionCommitment The commitment of the transaction that created the output. Hex-encoded with 0x prefix. - * @param outputCommitmentProof The proof of the output commitment. - */ - constructor( - slot: SlotIndex, - outputIndex: number, - transactionCommitment: HexEncodedString, - outputCommitmentProof: OutputCommitmentProof, - ) { - this.slot = slot; - this.outputIndex = outputIndex; - this.transactionCommitment = transactionCommitment; - this.outputCommitmentProof = outputCommitmentProof; - } -} diff --git a/bindings/nodejs/lib/types/models/api/output-metadata-response.ts b/bindings/nodejs/lib/types/models/api/output-metadata-response.ts deleted file mode 100644 index baf9c63b4d..0000000000 --- a/bindings/nodejs/lib/types/models/api/output-metadata-response.ts +++ /dev/null @@ -1,102 +0,0 @@ -// Copyright 2023 IOTA Stiftung -// SPDX-License-Identifier: Apache-2.0 - -import { OutputIdProof, TransactionId } from '../..'; -import { BlockId } from '../../block/id'; -import { Output, OutputId } from '../../block/output'; -import { SlotCommitmentId, SlotIndex } from '../../block/slot'; - -/** - * Metadata of the output if it is included in the ledger. - */ -export interface OutputInclusionMetadata { - /** - * Slot in which the output was included. - */ - slot: SlotIndex; - /** - * Transaction ID that created the output. - */ - transactionId: TransactionId; - /** - * Commitment ID that includes the creation of the output. - */ - commitmentId?: SlotCommitmentId; -} - -/** - * Metadata of the output if it is marked as spent in the ledger. - */ -export interface OutputConsumptionMetadata { - /** - * Slot in which the output was spent. - */ - slot: SlotIndex; - /** - * Transaction ID that spent the output. - */ - transactionId: TransactionId; - /** - * Commitment ID that includes the spending of the output. - */ - commitmentId?: SlotCommitmentId; -} - -/** - * Metadata of an output. - */ -export interface OutputMetadataResponse { - /** - * The ID of the output. - */ - outputId: OutputId; - /** - * The ID of the block in which the output was included. - */ - blockId: BlockId; - /** - * Metadata of the output if it is included in the ledger. - */ - included: OutputInclusionMetadata; - /** - * Metadata of the output if it is marked as spent in the ledger. - */ - spent?: OutputConsumptionMetadata; - /** - * Latest commitment ID of the node. - */ - latestCommitmentId: SlotCommitmentId; -} - -/** - * An output with its output id proof and its metadata. - * Response of GET /api/core/v3/outputs/{outputId}/full. - */ -export class OutputWithMetadataResponse { - /** - * One of the possible output types. - */ - output!: Output; - /** - * The associated Output ID proof. - */ - outputIdProof!: OutputIdProof; - /** - * The metadata of the output. - */ - metadata!: OutputMetadataResponse; -} - -/** - * An output and its metadata. - */ -export class OutputWithMetadata { - /** - * One of the possible output types. - */ - output!: Output; - /** - * The metadata of the output. - */ - metadata!: OutputMetadataResponse; -} diff --git a/bindings/nodejs/lib/types/models/api/output-response.ts b/bindings/nodejs/lib/types/models/api/output-response.ts deleted file mode 100644 index 1a3c4fc53a..0000000000 --- a/bindings/nodejs/lib/types/models/api/output-response.ts +++ /dev/null @@ -1,25 +0,0 @@ -// Copyright 2023 IOTA Stiftung -// SPDX-License-Identifier: Apache-2.0 - -import { Output, OutputDiscriminator } from '../../block/output'; -import { OutputIdProof } from './output-id-proof'; - -import { Type } from 'class-transformer'; - -/** - * An output with its output id proof. - * Response of GET /api/core/v3/outputs/{outputId}. - */ -export class OutputResponse { - /** - * One of the possible output types. - */ - @Type(() => Output, { - discriminator: OutputDiscriminator, - }) - output!: Output; - /** - * The proof of the output identifier. - */ - outputIdProof!: OutputIdProof; -} diff --git a/bindings/nodejs/lib/types/models/api/response.ts b/bindings/nodejs/lib/types/models/api/response.ts deleted file mode 100644 index a4effad65e..0000000000 --- a/bindings/nodejs/lib/types/models/api/response.ts +++ /dev/null @@ -1,21 +0,0 @@ -// Copyright 2023 IOTA Stiftung -// SPDX-License-Identifier: Apache-2.0 - -/** - * Base response data. - */ -export interface Response { - /** - * Optional error in the response. - */ - error?: { - /** - * The code for the error response. - */ - code: string; - /** - * A more descriptive version of the error. - */ - message: string; - }; -} diff --git a/bindings/nodejs/lib/types/models/api/mana-rewards-response.ts b/bindings/nodejs/lib/types/models/api/rewards.ts similarity index 100% rename from bindings/nodejs/lib/types/models/api/mana-rewards-response.ts rename to bindings/nodejs/lib/types/models/api/rewards.ts diff --git a/bindings/nodejs/lib/types/models/api/routes-response.ts b/bindings/nodejs/lib/types/models/api/routes-response.ts deleted file mode 100644 index aaf8dbf016..0000000000 --- a/bindings/nodejs/lib/types/models/api/routes-response.ts +++ /dev/null @@ -1,12 +0,0 @@ -// Copyright 2023 IOTA Stiftung -// SPDX-License-Identifier: Apache-2.0 - -/** - * Response from the /routes endpoint. - */ -export interface RoutesResponse { - /** - * The routes the node exposes. - */ - routes: string[]; -} diff --git a/bindings/nodejs/lib/types/models/api/transaction-response.ts b/bindings/nodejs/lib/types/models/api/transaction-response.ts deleted file mode 100644 index 4d3ea506a7..0000000000 --- a/bindings/nodejs/lib/types/models/api/transaction-response.ts +++ /dev/null @@ -1,32 +0,0 @@ -// Copyright 2024 IOTA Stiftung -// SPDX-License-Identifier: Apache-2.0 - -import { TransactionState } from '../state'; -import { SlotIndex, TransactionId } from '../../block'; -import { TransactionFailureReason } from './transaction-failure-reason'; - -/** - * Metadata of a transaction. - */ -export interface TransactionMetadataResponse { - /** - * The transaction id. - */ - transactionId: TransactionId; - /** - * The transaction state. - */ - transactionState: TransactionState; - /** - * The slot of the earliest included valid block that contains an attachment of the transaction. - */ - earliestAttachmentSlot: SlotIndex; - /** - * If applicable, indicates the error that occurred during the transaction processing. - */ - transactionFailureReason?: TransactionFailureReason; - /** - * Contains the detailed error message that occurred during the transaction processing if the debug mode was activated in the retainer. - */ - transactionFailureDetails?: string; -} diff --git a/bindings/nodejs/lib/types/models/api/transaction-failure-reason.ts b/bindings/nodejs/lib/types/models/api/utxo.ts similarity index 63% rename from bindings/nodejs/lib/types/models/api/transaction-failure-reason.ts rename to bindings/nodejs/lib/types/models/api/utxo.ts index 0751ed0583..8c3017bb45 100644 --- a/bindings/nodejs/lib/types/models/api/transaction-failure-reason.ts +++ b/bindings/nodejs/lib/types/models/api/utxo.ts @@ -1,6 +1,266 @@ // Copyright 2024 IOTA Stiftung // SPDX-License-Identifier: Apache-2.0 +// Temp solution for not double parsing JSON +import { plainToInstance, Type } from 'class-transformer'; +import { BlockId, TransactionId } from '../../block/id'; +import { Output, OutputId, OutputDiscriminator } from '../../block/output'; +import { SlotCommitmentId, SlotIndex } from '../../block/slot'; +import { TransactionState } from '../state'; +import { HexEncodedString } from '../../utils'; + +/** + * OutputCommitmentProof types. + */ +export enum OutputCommitmentProofType { + /** Denotes a HashableNode. */ + HashableNode = 0, + /** Denotes a LeafHash. */ + LeafHash = 1, + /** Denotes a ValueHash. */ + ValueHash = 2, +} + +export abstract class OutputCommitmentProof { + readonly type: OutputCommitmentProofType; + + /** + * @param type The type of OutputCommitmentProof. + */ + constructor(type: OutputCommitmentProofType) { + this.type = type; + } + + /** + * Parse an OutputCommitmentProof from a plain JSON object. + */ + public static parse(data: any): OutputCommitmentProof { + if (data.type == OutputCommitmentProofType.HashableNode) { + return plainToInstance(HashableNode, data) as any as HashableNode; + } else if (data.type == OutputCommitmentProofType.LeafHash) { + return plainToInstance(LeafHash, data) as any as LeafHash; + } else if (data.type == OutputCommitmentProofType.ValueHash) { + return plainToInstance(ValueHash, data) as any as ValueHash; + } + throw new Error('Invalid JSON'); + } +} + +/** + * Contains the hashes of the left and right children of a node in the OutputCommitmentProof tree. + */ +export class HashableNode extends OutputCommitmentProof { + readonly l: OutputCommitmentProof; + readonly r: OutputCommitmentProof; + + /** + * @param l Output commitment proof of the left subtree. + * @param r Output commitment proof of the right subtree. + */ + constructor(l: OutputCommitmentProof, r: OutputCommitmentProof) { + super(OutputCommitmentProofType.HashableNode); + this.l = l; + this.r = r; + } +} + +/** + * Contains the hash of a leaf in the OutputCommitmentProof tree. + */ +export class LeafHash extends OutputCommitmentProof { + readonly hash: HexEncodedString; + + /** + * @param hash The hash of the leaf. + */ + constructor(hash: HexEncodedString) { + super(OutputCommitmentProofType.LeafHash); + this.hash = hash; + } +} + +/** + * Contains the hash of the value for which the OutputCommitmentProof is being computed. + */ +export class ValueHash extends OutputCommitmentProof { + readonly hash: HexEncodedString; + + /** + * @param hash The hash of the value. + */ + constructor(hash: HexEncodedString) { + super(OutputCommitmentProofType.ValueHash); + this.hash = hash; + } +} + +/** + * The proof of the output identifier. + */ +export class OutputIdProof { + readonly slot: SlotIndex; + readonly outputIndex: number; + readonly transactionCommitment: HexEncodedString; + readonly outputCommitmentProof: OutputCommitmentProof; + + /** + * @param slot The slot index of the output. + * @param outputIndex The index of the output within the corresponding transaction. + * @param transactionCommitment The commitment of the transaction that created the output. Hex-encoded with 0x prefix. + * @param outputCommitmentProof The proof of the output commitment. + */ + constructor( + slot: SlotIndex, + outputIndex: number, + transactionCommitment: HexEncodedString, + outputCommitmentProof: OutputCommitmentProof, + ) { + this.slot = slot; + this.outputIndex = outputIndex; + this.transactionCommitment = transactionCommitment; + this.outputCommitmentProof = outputCommitmentProof; + } +} + +/** + * An output with its output id proof. + * Response of GET /api/core/v3/outputs/{outputId}. + */ +export class OutputResponse { + /** + * One of the possible output types. + */ + @Type(() => Output, { + discriminator: OutputDiscriminator, + }) + output!: Output; + /** + * The proof of the output identifier. + */ + outputIdProof!: OutputIdProof; +} + +/** + * Metadata of the output if it is included in the ledger. + */ +export interface OutputInclusionMetadata { + /** + * Slot in which the output was included. + */ + slot: SlotIndex; + /** + * Transaction ID that created the output. + */ + transactionId: TransactionId; + /** + * Commitment ID that includes the creation of the output. + */ + commitmentId?: SlotCommitmentId; +} + +/** + * Metadata of the output if it is marked as spent in the ledger. + */ +export interface OutputConsumptionMetadata { + /** + * Slot in which the output was spent. + */ + slot: SlotIndex; + /** + * Transaction ID that spent the output. + */ + transactionId: TransactionId; + /** + * Commitment ID that includes the spending of the output. + */ + commitmentId?: SlotCommitmentId; +} + +/** + * Metadata of an output. + */ +export interface OutputMetadataResponse { + /** + * The ID of the output. + */ + outputId: OutputId; + /** + * The ID of the block in which the output was included. + */ + blockId: BlockId; + /** + * Metadata of the output if it is included in the ledger. + */ + included: OutputInclusionMetadata; + /** + * Metadata of the output if it is marked as spent in the ledger. + */ + spent?: OutputConsumptionMetadata; + /** + * Latest commitment ID of the node. + */ + latestCommitmentId: SlotCommitmentId; +} + +/** + * An output with its output id proof and its metadata. + * Response of GET /api/core/v3/outputs/{outputId}/full. + */ +export class OutputWithMetadataResponse { + /** + * One of the possible output types. + */ + output!: Output; + /** + * The associated Output ID proof. + */ + outputIdProof!: OutputIdProof; + /** + * The metadata of the output. + */ + metadata!: OutputMetadataResponse; +} + +/** + * An output and its metadata. + */ +export class OutputWithMetadata { + /** + * One of the possible output types. + */ + output!: Output; + /** + * The metadata of the output. + */ + metadata!: OutputMetadataResponse; +} + +/** + * Metadata of a transaction. + */ +export interface TransactionMetadataResponse { + /** + * The transaction id. + */ + transactionId: TransactionId; + /** + * The transaction state. + */ + transactionState: TransactionState; + /** + * The slot of the earliest included valid block that contains an attachment of the transaction. + */ + earliestAttachmentSlot: SlotIndex; + /** + * If applicable, indicates the error that occurred during the transaction processing. + */ + transactionFailureReason?: TransactionFailureReason; + /** + * Contains the detailed error message that occurred during the transaction processing if the debug mode was activated in the retainer. + */ + transactionFailureDetails?: string; +} + /** * Reason for transaction failure. */ diff --git a/bindings/nodejs/lib/types/models/api/validators-response.ts b/bindings/nodejs/lib/types/models/api/validators.ts similarity index 100% rename from bindings/nodejs/lib/types/models/api/validators-response.ts rename to bindings/nodejs/lib/types/models/api/validators.ts diff --git a/bindings/nodejs/tests/client/messageMethods.spec.ts b/bindings/nodejs/tests/client/messageMethods.spec.ts index 7ef75504c4..fc73ca2591 100644 --- a/bindings/nodejs/tests/client/messageMethods.spec.ts +++ b/bindings/nodejs/tests/client/messageMethods.spec.ts @@ -49,7 +49,7 @@ describe.skip('Block methods', () => { ); const block = await secretManager.signBlock(unsignedBlock, chain); - const blockId = await client.postBlockRaw(block); + const blockId = await client.postBlock(block); expect(blockId).toBeValidBlockId(); }); diff --git a/bindings/nodejs/tests/types/protocol_parameters.spec.ts b/bindings/nodejs/tests/types/protocol_parameters.spec.ts index 955564beb7..e3dd3c4816 100644 --- a/bindings/nodejs/tests/types/protocol_parameters.spec.ts +++ b/bindings/nodejs/tests/types/protocol_parameters.spec.ts @@ -5,7 +5,7 @@ import 'reflect-metadata'; import { expect, describe, it } from '@jest/globals'; import * as protocol_parameters from '../../../../sdk/tests/types/fixtures/protocol_parameters.json'; -import { ProtocolParameters } from '../../lib/types/models/api/info/node-info-protocol'; +import { ProtocolParameters } from '../../lib/types/models/api'; import { Utils } from '../../'; describe('ProtocolParameters tests', () => { diff --git a/bindings/nodejs/tests/utils/utils.spec.ts b/bindings/nodejs/tests/utils/utils.spec.ts index 88d2399ea8..683f93de8b 100644 --- a/bindings/nodejs/tests/utils/utils.spec.ts +++ b/bindings/nodejs/tests/utils/utils.spec.ts @@ -9,7 +9,7 @@ import { BasicOutput, BlockId, OutputId, TransactionId, Utils } from '../../out' import '../customMatchers'; import { SlotCommitment } from '../../out/types/block/slot'; import * as protocol_parameters from '../../../../sdk/tests/types/fixtures/protocol_parameters.json'; -import { ProtocolParameters } from '../../lib/types/models/api/info/node-info-protocol'; +import { ProtocolParameters } from '../../lib/types/models/api'; describe('Utils methods', () => { it('invalid mnemonic error', () => {