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(
|
getBlock(
|
||||||
blockHeight: number | string
|
blockHeight: number | string
|
||||||
): Promise<EndpointsUrl[Endpoints.blocksDetail]>;
|
): Promise<EndpointsResponse[Endpoints.blocksDetail]>;
|
||||||
|
|
||||||
getTransaction<O = TransactionOperations.CREATE>(
|
getTransaction<O = TransactionOperations.CREATE>(
|
||||||
transactionId: string
|
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(
|
listOutputs(
|
||||||
publicKey: string,
|
publicKey: string,
|
||||||
spent?: boolean
|
spent?: boolean
|
||||||
): Promise<EndpointsUrl[Endpoints.outputs]>;
|
): Promise<EndpointsResponse[Endpoints.outputs]>;
|
||||||
|
|
||||||
listTransactions<O = TransactionOperations.CREATE>(
|
listTransactions(
|
||||||
assetId: string,
|
assetId: string,
|
||||||
operation: O
|
operation?: TransactionOperations
|
||||||
): Promise<EndpointsUrl<O>[Endpoints.transactions]>;
|
): Promise<EndpointsResponse<typeof operation>[Endpoints.transactions]>;
|
||||||
|
|
||||||
postTransaction<
|
postTransaction<
|
||||||
O = TransactionOperations.CREATE,
|
O = TransactionOperations.CREATE,
|
||||||
@ -130,7 +130,7 @@ export default class Connection {
|
|||||||
M = Record<string, any>
|
M = Record<string, any>
|
||||||
>(
|
>(
|
||||||
transaction: TransactionCommon<O>
|
transaction: TransactionCommon<O>
|
||||||
): Promise<EndpointsUrl<O, A, M>[Endpoints.transactionsCommit]>;
|
): Promise<EndpointsResponse<O, A, M>[Endpoints.transactionsCommit]>;
|
||||||
|
|
||||||
postTransactionSync<
|
postTransactionSync<
|
||||||
O = TransactionOperations.CREATE,
|
O = TransactionOperations.CREATE,
|
||||||
@ -138,7 +138,7 @@ export default class Connection {
|
|||||||
M = Record<string, any>
|
M = Record<string, any>
|
||||||
>(
|
>(
|
||||||
transaction: TransactionCommon<O>
|
transaction: TransactionCommon<O>
|
||||||
): Promise<EndpointsUrl<O, A, M>[Endpoints.transactionsSync]>;
|
): Promise<EndpointsResponse<O, A, M>[Endpoints.transactionsSync]>;
|
||||||
|
|
||||||
postTransactionAsync<
|
postTransactionAsync<
|
||||||
O = TransactionOperations.CREATE,
|
O = TransactionOperations.CREATE,
|
||||||
@ -146,7 +146,7 @@ export default class Connection {
|
|||||||
M = Record<string, any>
|
M = Record<string, any>
|
||||||
>(
|
>(
|
||||||
transaction: TransactionCommon<O>
|
transaction: TransactionCommon<O>
|
||||||
): Promise<EndpointsUrl<O, A, M>[Endpoints.transactionsAsync]>;
|
): Promise<EndpointsResponse<O, A, M>[Endpoints.transactionsAsync]>;
|
||||||
|
|
||||||
postTransactionCommit<
|
postTransactionCommit<
|
||||||
O = TransactionOperations.CREATE,
|
O = TransactionOperations.CREATE,
|
||||||
@ -154,9 +154,9 @@ export default class Connection {
|
|||||||
M = Record<string, any>
|
M = Record<string, any>
|
||||||
>(
|
>(
|
||||||
transaction: TransactionCommon<O>
|
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,
|
PreimageSha256,
|
||||||
ThresholdSha256,
|
ThresholdSha256,
|
||||||
} from 'crypto-conditions';
|
} from 'crypto-conditions';
|
||||||
|
import { TypeId } from 'crypto-conditions/types/types';
|
||||||
import {
|
import {
|
||||||
Ed25519Sha256JSONCondition,
|
Ed25519Sha256JSONCondition,
|
||||||
JSONCondition,
|
JSONConditions,
|
||||||
|
JSONConditionUnion,
|
||||||
PreimageSha256JSONCondition,
|
PreimageSha256JSONCondition,
|
||||||
ThresholdSha256JSONCondition,
|
ThresholdSha256JSONCondition,
|
||||||
} from './utils/ccJsonify';
|
} from './utils/ccJsonify';
|
||||||
@ -19,7 +21,6 @@ export interface TransactionInput {
|
|||||||
} | null;
|
} | null;
|
||||||
owners_before: string[];
|
owners_before: string[];
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface TransactionOutput {
|
export interface TransactionOutput {
|
||||||
amount: string;
|
amount: string;
|
||||||
// TODO: specifiy JSON conditions
|
// TODO: specifiy JSON conditions
|
||||||
@ -81,6 +82,11 @@ export interface TransferTransaction<M = Record<string, unknown>>
|
|||||||
operation: TransactionOperations.TRANSFER;
|
operation: TransactionOperations.TRANSFER;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface TransactionUnspentOutput {
|
||||||
|
tx: TransactionCommon;
|
||||||
|
output_index: number;
|
||||||
|
}
|
||||||
|
|
||||||
interface TxTemplate {
|
interface TxTemplate {
|
||||||
id: null;
|
id: null;
|
||||||
operation: null;
|
operation: null;
|
||||||
@ -102,55 +108,55 @@ export default class Transaction {
|
|||||||
transaction: CreateTransaction | TransferTransaction
|
transaction: CreateTransaction | TransferTransaction
|
||||||
): string;
|
): string;
|
||||||
|
|
||||||
|
static makeEd25519Condition(publicKey: string): Ed25519Sha256JSONCondition;
|
||||||
|
|
||||||
static makeEd25519Condition(
|
static makeEd25519Condition(
|
||||||
publicKey: string,
|
publicKey: string,
|
||||||
json = true
|
json: true
|
||||||
): Ed25519Sha256JSONCondition;
|
): Ed25519Sha256JSONCondition;
|
||||||
|
|
||||||
static makeEd25519Condition(publicKey: string, json = false): Ed25519Sha256;
|
static makeEd25519Condition(publicKey: string, json: false): Ed25519Sha256;
|
||||||
|
|
||||||
// static makeEd25519Condition(publicKey: string): Ed25519Sha256JSONCondition;
|
|
||||||
|
|
||||||
static makeEd25519Condition(
|
static makeEd25519Condition(
|
||||||
publicKey: string,
|
publicKey: string,
|
||||||
json?: boolean
|
json: boolean = true
|
||||||
): Ed25519Sha256 | Ed25519Sha256JSONCondition;
|
): Ed25519Sha256 | Ed25519Sha256JSONCondition;
|
||||||
|
|
||||||
|
static makeSha256Condition(preimage: string): PreimageSha256JSONCondition;
|
||||||
|
|
||||||
static makeSha256Condition(
|
static makeSha256Condition(
|
||||||
preimage: string,
|
preimage: string,
|
||||||
json = true
|
json: true
|
||||||
): PreimageSha256JSONCondition;
|
): PreimageSha256JSONCondition;
|
||||||
|
|
||||||
static makeSha256Condition(preimage: string, json = false): PreimageSha256;
|
static makeSha256Condition(preimage: string, json: false): PreimageSha256;
|
||||||
|
|
||||||
// static makeSha256Condition(preimage: string): PreimageSha256JSONCondition;
|
|
||||||
|
|
||||||
static makeSha256Condition(
|
static makeSha256Condition(
|
||||||
preimage: string,
|
preimage: string,
|
||||||
json?: boolean
|
json: boolean = true
|
||||||
): PreimageSha256 | PreimageSha256JSONCondition;
|
): PreimageSha256 | PreimageSha256JSONCondition;
|
||||||
|
|
||||||
static makeThresholdCondition(
|
static makeThresholdCondition(
|
||||||
threshold: number,
|
threshold: number,
|
||||||
subconditions: (string | Fulfillment)[],
|
subconditions: (string | Fulfillment)[]
|
||||||
json = true
|
|
||||||
): ThresholdSha256JSONCondition;
|
): ThresholdSha256JSONCondition;
|
||||||
|
|
||||||
static makeThresholdCondition(
|
static makeThresholdCondition(
|
||||||
threshold: number,
|
threshold: number,
|
||||||
subconditions: (string | Fulfillment)[],
|
subconditions: (string | Fulfillment)[],
|
||||||
json = false
|
json: true
|
||||||
): ThresholdSha256;
|
): ThresholdSha256JSONCondition;
|
||||||
|
|
||||||
// static makeThresholdCondition(
|
|
||||||
// threshold: number,
|
|
||||||
// subconditions: (string | Fulfillment)[]
|
|
||||||
// ): ThresholdSha256JSONCondition;
|
|
||||||
|
|
||||||
static makeThresholdCondition(
|
static makeThresholdCondition(
|
||||||
threshold: number,
|
threshold: number,
|
||||||
subconditions: (string | Fulfillment)[],
|
subconditions: (string | Fulfillment)[],
|
||||||
json?: boolean
|
json: false
|
||||||
|
): ThresholdSha256;
|
||||||
|
|
||||||
|
static makeThresholdCondition(
|
||||||
|
threshold: number,
|
||||||
|
subconditions: (string | Fulfillment)[],
|
||||||
|
json: boolean = true
|
||||||
): ThresholdSha256 | ThresholdSha256JSONCondition;
|
): ThresholdSha256 | ThresholdSha256JSONCondition;
|
||||||
|
|
||||||
static makeInputTemplate(
|
static makeInputTemplate(
|
||||||
@ -160,8 +166,13 @@ export default class Transaction {
|
|||||||
): TransactionInput;
|
): TransactionInput;
|
||||||
|
|
||||||
static makeOutput(
|
static makeOutput(
|
||||||
condition: JSONCondition,
|
condition: JSONConditionUnion,
|
||||||
amount: string
|
amount: string = '1'
|
||||||
|
): TransactionOutput;
|
||||||
|
|
||||||
|
static makeOutput<T = TypeId.Ed25519Sha256>(
|
||||||
|
condition: JSONConditions[T],
|
||||||
|
amount: string = '1'
|
||||||
): TransactionOutput;
|
): TransactionOutput;
|
||||||
|
|
||||||
static makeTransactionTemplate(): TxTemplate;
|
static makeTransactionTemplate(): TxTemplate;
|
||||||
@ -189,7 +200,7 @@ export default class Transaction {
|
|||||||
): CreateTransaction<A, M>;
|
): CreateTransaction<A, M>;
|
||||||
|
|
||||||
static makeTransferTransaction<M = Record<string, any>>(
|
static makeTransferTransaction<M = Record<string, any>>(
|
||||||
unspentOutputs: TransactionOutput[],
|
unspentOutputs: TransactionUnspentOutput[],
|
||||||
outputs: TransactionOutput[],
|
outputs: TransactionOutput[],
|
||||||
metadata: M
|
metadata: M
|
||||||
): TransferTransaction<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;
|
uri: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface Ed25519Sha256JSONCondition extends BaseJSONCondition {
|
export interface Ed25519Sha256JSONCondition extends BaseJSONCondition {
|
||||||
details: { type: TypeName.Ed25519Sha256; publicKey?: string };
|
details: { type: TypeName.Ed25519Sha256; publicKey?: string };
|
||||||
}
|
}
|
||||||
|
export interface PreimageSha256JSONCondition extends BaseJSONCondition {
|
||||||
interface PreimageSha256JSONCondition extends BaseJSONCondition {
|
|
||||||
details: {
|
details: {
|
||||||
type: TypeName.PreimageSha256;
|
type: TypeName.PreimageSha256;
|
||||||
type_id: 0;
|
type_id: 0;
|
||||||
@ -30,14 +29,19 @@ interface PreimageSha256JSONCondition extends BaseJSONCondition {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
interface ThresholdSha256JSONCondition extends BaseJSONCondition {
|
export interface ThresholdSha256JSONCondition extends BaseJSONCondition {
|
||||||
details: {
|
details: {
|
||||||
type: TypeName.ThresholdSha256;
|
type: TypeName.ThresholdSha256;
|
||||||
subConditions: (Ed25519Sha256JSONCondition | PreimageSha256JSONCondition)[];
|
subConditions: (Ed25519Sha256JSONCondition | PreimageSha256JSONCondition)[];
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface JSONCondition {
|
export type JSONConditionUnion =
|
||||||
|
| PreimageSha256JSONCondition
|
||||||
|
| Ed25519Sha256JSONCondition
|
||||||
|
| ThresholdSha256JSONCondition;
|
||||||
|
|
||||||
|
export interface JSONConditions {
|
||||||
[TypeId.ThresholdSha256]: ThresholdSha256JSONCondition;
|
[TypeId.ThresholdSha256]: ThresholdSha256JSONCondition;
|
||||||
[TypeId.PreimageSha256]: PreimageSha256JSONCondition;
|
[TypeId.PreimageSha256]: PreimageSha256JSONCondition;
|
||||||
[TypeId.Ed25519Sha256]: Ed25519Sha256JSONCondition;
|
[TypeId.Ed25519Sha256]: Ed25519Sha256JSONCondition;
|
||||||
@ -45,4 +49,4 @@ export interface JSONCondition {
|
|||||||
|
|
||||||
export default function ccJsonify<T = TypeId.Ed25519Sha256>(
|
export default function ccJsonify<T = TypeId.Ed25519Sha256>(
|
||||||
fulfillment: Fulfillment | Condition
|
fulfillment: Fulfillment | Condition
|
||||||
): JSONCondition[T];
|
): JSONConditions[T];
|
||||||
|
Loading…
Reference in New Issue
Block a user