mirror of
https://github.com/bigchaindb/js-bigchaindb-driver.git
synced 2024-11-22 01:36:56 +01:00
fix: refine types definitions
This commit is contained in:
parent
5f6bef65c5
commit
84bd4efe03
26
types/connection.d.ts
vendored
26
types/connection.d.ts
vendored
@ -106,23 +106,23 @@ export default class Connection {
|
||||
|
||||
getBlock(
|
||||
blockHeight: number | string
|
||||
): Promise<EndpointsUrl[Endpoints.blocksDetail]>;
|
||||
): Promise<EndpointsResponse[Endpoints.blocksDetail]>;
|
||||
|
||||
getTransaction<O = TransactionOperations.CREATE>(
|
||||
transactionId: string
|
||||
): Promise<EndpointsUrl<O>[Endpoints.transactionsDetail]>;
|
||||
): Promise<EndpointsResponse<O>[Endpoints.transactionsDetail]>;
|
||||
|
||||
listBlocks(transactionId: string): Promise<EndpointsUrl[Endpoints.blocks]>;
|
||||
listBlocks(transactionId: string): Promise<EndpointsResponse[Endpoints.blocks]>;
|
||||
|
||||
listOutputs(
|
||||
publicKey: string,
|
||||
spent?: boolean
|
||||
): Promise<EndpointsUrl[Endpoints.outputs]>;
|
||||
): Promise<EndpointsResponse[Endpoints.outputs]>;
|
||||
|
||||
listTransactions<O = TransactionOperations.CREATE>(
|
||||
listTransactions(
|
||||
assetId: string,
|
||||
operation: O
|
||||
): Promise<EndpointsUrl<O>[Endpoints.transactions]>;
|
||||
operation?: TransactionOperations
|
||||
): Promise<EndpointsResponse<typeof operation>[Endpoints.transactions]>;
|
||||
|
||||
postTransaction<
|
||||
O = TransactionOperations.CREATE,
|
||||
@ -130,7 +130,7 @@ export default class Connection {
|
||||
M = Record<string, any>
|
||||
>(
|
||||
transaction: TransactionCommon<O>
|
||||
): Promise<EndpointsUrl<O, A, M>[Endpoints.transactionsCommit]>;
|
||||
): Promise<EndpointsResponse<O, A, M>[Endpoints.transactionsCommit]>;
|
||||
|
||||
postTransactionSync<
|
||||
O = TransactionOperations.CREATE,
|
||||
@ -138,7 +138,7 @@ export default class Connection {
|
||||
M = Record<string, any>
|
||||
>(
|
||||
transaction: TransactionCommon<O>
|
||||
): Promise<EndpointsUrl<O, A, M>[Endpoints.transactionsSync]>;
|
||||
): Promise<EndpointsResponse<O, A, M>[Endpoints.transactionsSync]>;
|
||||
|
||||
postTransactionAsync<
|
||||
O = TransactionOperations.CREATE,
|
||||
@ -146,7 +146,7 @@ export default class Connection {
|
||||
M = Record<string, any>
|
||||
>(
|
||||
transaction: TransactionCommon<O>
|
||||
): Promise<EndpointsUrl<O, A, M>[Endpoints.transactionsAsync]>;
|
||||
): Promise<EndpointsResponse<O, A, M>[Endpoints.transactionsAsync]>;
|
||||
|
||||
postTransactionCommit<
|
||||
O = TransactionOperations.CREATE,
|
||||
@ -154,9 +154,9 @@ export default class Connection {
|
||||
M = Record<string, any>
|
||||
>(
|
||||
transaction: TransactionCommon<O>
|
||||
): Promise<EndpointsUrl<O, A, M>[Endpoints.transactionsCommit]>;
|
||||
): Promise<EndpointsResponse<O, A, M>[Endpoints.transactionsCommit]>;
|
||||
|
||||
searchAssets(search: string): Promise<EndpointsUrl[Endpoints.assets]>;
|
||||
searchAssets(search: string): Promise<EndpointsResponse[Endpoints.assets]>;
|
||||
|
||||
searchMetadata(search: string): Promise<EndpointsUrl[Endpoints.metadata]>;
|
||||
searchMetadata(search: string): Promise<EndpointsResponse[Endpoints.metadata]>;
|
||||
}
|
||||
|
61
types/transaction.d.ts
vendored
61
types/transaction.d.ts
vendored
@ -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<M = Record<string, unknown>>
|
||||
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<T = TypeId.Ed25519Sha256>(
|
||||
condition: JSONConditions[T],
|
||||
amount: string = '1'
|
||||
): TransactionOutput;
|
||||
|
||||
static makeTransactionTemplate(): TxTemplate;
|
||||
@ -189,7 +200,7 @@ export default class Transaction {
|
||||
): CreateTransaction<A, M>;
|
||||
|
||||
static makeTransferTransaction<M = Record<string, any>>(
|
||||
unspentOutputs: TransactionOutput[],
|
||||
unspentOutputs: TransactionUnspentOutput[],
|
||||
outputs: TransactionOutput[],
|
||||
metadata: M
|
||||
): TransferTransaction<M>;
|
||||
|
16
types/utils/ccJsonify.d.ts
vendored
16
types/utils/ccJsonify.d.ts
vendored
@ -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<T = TypeId.Ed25519Sha256>(
|
||||
fulfillment: Fulfillment | Condition
|
||||
): JSONCondition[T];
|
||||
): JSONConditions[T];
|
||||
|
Loading…
Reference in New Issue
Block a user