diff --git a/types/connection.d.ts b/types/connection.d.ts index 47e08b2..336f8f4 100644 --- a/types/connection.d.ts +++ b/types/connection.d.ts @@ -106,23 +106,23 @@ export default class Connection { getBlock( blockHeight: number | string - ): Promise; + ): Promise; getTransaction( transactionId: string - ): Promise[Endpoints.transactionsDetail]>; + ): Promise[Endpoints.transactionsDetail]>; - listBlocks(transactionId: string): Promise; + listBlocks(transactionId: string): Promise; listOutputs( publicKey: string, spent?: boolean - ): Promise; + ): Promise; - listTransactions( + listTransactions( assetId: string, - operation: O - ): Promise[Endpoints.transactions]>; + operation?: TransactionOperations + ): Promise[Endpoints.transactions]>; postTransaction< O = TransactionOperations.CREATE, @@ -130,7 +130,7 @@ export default class Connection { M = Record >( transaction: TransactionCommon - ): Promise[Endpoints.transactionsCommit]>; + ): Promise[Endpoints.transactionsCommit]>; postTransactionSync< O = TransactionOperations.CREATE, @@ -138,7 +138,7 @@ export default class Connection { M = Record >( transaction: TransactionCommon - ): Promise[Endpoints.transactionsSync]>; + ): Promise[Endpoints.transactionsSync]>; postTransactionAsync< O = TransactionOperations.CREATE, @@ -146,7 +146,7 @@ export default class Connection { M = Record >( transaction: TransactionCommon - ): Promise[Endpoints.transactionsAsync]>; + ): Promise[Endpoints.transactionsAsync]>; postTransactionCommit< O = TransactionOperations.CREATE, @@ -154,9 +154,9 @@ export default class Connection { M = Record >( transaction: TransactionCommon - ): Promise[Endpoints.transactionsCommit]>; + ): Promise[Endpoints.transactionsCommit]>; - searchAssets(search: string): Promise; + searchAssets(search: string): Promise; - searchMetadata(search: string): Promise; + searchMetadata(search: string): Promise; } diff --git a/types/transaction.d.ts b/types/transaction.d.ts index 0f3f711..752cc3c 100644 --- a/types/transaction.d.ts +++ b/types/transaction.d.ts @@ -4,9 +4,11 @@ import type { PreimageSha256, ThresholdSha256, } from 'crypto-conditions'; +import { TypeId } from 'crypto-conditions/types/types'; import { Ed25519Sha256JSONCondition, - JSONCondition, + JSONConditions, + JSONConditionUnion, PreimageSha256JSONCondition, ThresholdSha256JSONCondition, } from './utils/ccJsonify'; @@ -19,7 +21,6 @@ export interface TransactionInput { } | null; owners_before: string[]; } - export interface TransactionOutput { amount: string; // TODO: specifiy JSON conditions @@ -81,6 +82,11 @@ export interface TransferTransaction> operation: TransactionOperations.TRANSFER; } +export interface TransactionUnspentOutput { + tx: TransactionCommon; + output_index: number; +} + interface TxTemplate { id: null; operation: null; @@ -102,55 +108,55 @@ export default class Transaction { transaction: CreateTransaction | TransferTransaction ): string; + static makeEd25519Condition(publicKey: string): Ed25519Sha256JSONCondition; + static makeEd25519Condition( publicKey: string, - json = true + json: true ): Ed25519Sha256JSONCondition; - static makeEd25519Condition(publicKey: string, json = false): Ed25519Sha256; - - // static makeEd25519Condition(publicKey: string): Ed25519Sha256JSONCondition; + static makeEd25519Condition(publicKey: string, json: false): Ed25519Sha256; static makeEd25519Condition( publicKey: string, - json?: boolean + json: boolean = true ): Ed25519Sha256 | Ed25519Sha256JSONCondition; + static makeSha256Condition(preimage: string): PreimageSha256JSONCondition; + static makeSha256Condition( preimage: string, - json = true + json: true ): PreimageSha256JSONCondition; - static makeSha256Condition(preimage: string, json = false): PreimageSha256; - - // static makeSha256Condition(preimage: string): PreimageSha256JSONCondition; + static makeSha256Condition(preimage: string, json: false): PreimageSha256; static makeSha256Condition( preimage: string, - json?: boolean + json: boolean = true ): PreimageSha256 | PreimageSha256JSONCondition; static makeThresholdCondition( threshold: number, - subconditions: (string | Fulfillment)[], - json = true + subconditions: (string | Fulfillment)[] ): ThresholdSha256JSONCondition; static makeThresholdCondition( threshold: number, subconditions: (string | Fulfillment)[], - json = false - ): ThresholdSha256; - - // static makeThresholdCondition( - // threshold: number, - // subconditions: (string | Fulfillment)[] - // ): ThresholdSha256JSONCondition; + json: true + ): ThresholdSha256JSONCondition; static makeThresholdCondition( threshold: number, subconditions: (string | Fulfillment)[], - json?: boolean + json: false + ): ThresholdSha256; + + static makeThresholdCondition( + threshold: number, + subconditions: (string | Fulfillment)[], + json: boolean = true ): ThresholdSha256 | ThresholdSha256JSONCondition; static makeInputTemplate( @@ -160,8 +166,13 @@ export default class Transaction { ): TransactionInput; static makeOutput( - condition: JSONCondition, - amount: string + condition: JSONConditionUnion, + amount: string = '1' + ): TransactionOutput; + + static makeOutput( + condition: JSONConditions[T], + amount: string = '1' ): TransactionOutput; static makeTransactionTemplate(): TxTemplate; @@ -189,7 +200,7 @@ export default class Transaction { ): CreateTransaction; static makeTransferTransaction>( - unspentOutputs: TransactionOutput[], + unspentOutputs: TransactionUnspentOutput[], outputs: TransactionOutput[], metadata: M ): TransferTransaction; diff --git a/types/utils/ccJsonify.d.ts b/types/utils/ccJsonify.d.ts index fe7eab2..717341a 100644 --- a/types/utils/ccJsonify.d.ts +++ b/types/utils/ccJsonify.d.ts @@ -16,11 +16,10 @@ interface BaseJSONCondition { uri: string; } -interface Ed25519Sha256JSONCondition extends BaseJSONCondition { +export interface Ed25519Sha256JSONCondition extends BaseJSONCondition { details: { type: TypeName.Ed25519Sha256; publicKey?: string }; } - -interface PreimageSha256JSONCondition extends BaseJSONCondition { +export interface PreimageSha256JSONCondition extends BaseJSONCondition { details: { type: TypeName.PreimageSha256; type_id: 0; @@ -30,14 +29,19 @@ interface PreimageSha256JSONCondition extends BaseJSONCondition { }; } -interface ThresholdSha256JSONCondition extends BaseJSONCondition { +export interface ThresholdSha256JSONCondition extends BaseJSONCondition { details: { type: TypeName.ThresholdSha256; subConditions: (Ed25519Sha256JSONCondition | PreimageSha256JSONCondition)[]; }; } -export interface JSONCondition { +export type JSONConditionUnion = + | PreimageSha256JSONCondition + | Ed25519Sha256JSONCondition + | ThresholdSha256JSONCondition; + +export interface JSONConditions { [TypeId.ThresholdSha256]: ThresholdSha256JSONCondition; [TypeId.PreimageSha256]: PreimageSha256JSONCondition; [TypeId.Ed25519Sha256]: Ed25519Sha256JSONCondition; @@ -45,4 +49,4 @@ export interface JSONCondition { export default function ccJsonify( fulfillment: Fulfillment | Condition -): JSONCondition[T]; +): JSONConditions[T];