mirror of
https://github.com/bigchaindb/js-bigchaindb-driver.git
synced 2024-06-15 17:13:18 +02:00
207 lines
4.9 KiB
TypeScript
207 lines
4.9 KiB
TypeScript
|
import type {
|
||
|
Ed25519Sha256,
|
||
|
Fulfillment,
|
||
|
PreimageSha256,
|
||
|
ThresholdSha256,
|
||
|
} from 'crypto-conditions';
|
||
|
import {
|
||
|
Ed25519Sha256JSONCondition,
|
||
|
JSONCondition,
|
||
|
PreimageSha256JSONCondition,
|
||
|
ThresholdSha256JSONCondition,
|
||
|
} from './utils/ccJsonify';
|
||
|
|
||
|
export interface TransactionInput {
|
||
|
fulfillment: string;
|
||
|
fulfills: {
|
||
|
output_index: number;
|
||
|
transaction_id: string;
|
||
|
} | null;
|
||
|
owners_before: string[];
|
||
|
}
|
||
|
|
||
|
export interface TransactionOutput {
|
||
|
amount: string;
|
||
|
// TODO: specifiy JSON conditions
|
||
|
condition: any[];
|
||
|
public_keys: string[];
|
||
|
}
|
||
|
|
||
|
export enum TransactionOperations {
|
||
|
CREATE = 'CREATE',
|
||
|
TRANSFER = 'TRANSFER',
|
||
|
}
|
||
|
|
||
|
export interface TransactionCommon<
|
||
|
O = TransactionOperations,
|
||
|
A = Record<string, unknown>,
|
||
|
M = Record<string, unknown>
|
||
|
> {
|
||
|
id?: string;
|
||
|
inputs: TransactionInput[];
|
||
|
outputs: TransactionOutput[];
|
||
|
version: string;
|
||
|
metadata: M;
|
||
|
operation: O;
|
||
|
asset: TransactionAssetMap<O, A>;
|
||
|
}
|
||
|
|
||
|
export interface TransactionCommonSigned<
|
||
|
O = TransactionOperations,
|
||
|
A = Record<string, unknown>,
|
||
|
M = Record<string, unknown>
|
||
|
> extends Omit<TransactionCommon<O, A, M>, 'id'> {
|
||
|
id: string;
|
||
|
}
|
||
|
|
||
|
export type TransactionAssetMap<
|
||
|
Operation,
|
||
|
A = Record<string, unknown>
|
||
|
> = Operation extends TransactionOperations.CREATE
|
||
|
? {
|
||
|
data: A;
|
||
|
}
|
||
|
: {
|
||
|
id: string;
|
||
|
};
|
||
|
|
||
|
export interface CreateTransaction<
|
||
|
A = Record<string, unknown>,
|
||
|
M = Record<string, unknown>
|
||
|
> extends TransactionCommon<TransactionOperations.CREATE, A, M> {
|
||
|
id: string;
|
||
|
asset: TransactionAssetMap<TransactionOperations.CREATE, A>;
|
||
|
operation: TransactionOperations.CREATE;
|
||
|
}
|
||
|
|
||
|
export interface TransferTransaction<M = Record<string, unknown>>
|
||
|
extends TransactionCommon<TransactionOperations.TRANSFER, any, M> {
|
||
|
id: string;
|
||
|
asset: TransactionAssetMap<TransactionOperations.TRANSFER>;
|
||
|
operation: TransactionOperations.TRANSFER;
|
||
|
}
|
||
|
|
||
|
interface TxTemplate {
|
||
|
id: null;
|
||
|
operation: null;
|
||
|
outputs: [];
|
||
|
inputs: [];
|
||
|
metadata: null;
|
||
|
asset: null;
|
||
|
version: '2.0';
|
||
|
}
|
||
|
|
||
|
declare function DelegateSignFunction(
|
||
|
serializedTransaction: string,
|
||
|
input: TransactionInput,
|
||
|
index?: number
|
||
|
): string;
|
||
|
|
||
|
export default class Transaction {
|
||
|
static serializeTransactionIntoCanonicalString(
|
||
|
transaction: CreateTransaction | TransferTransaction
|
||
|
): string;
|
||
|
|
||
|
static makeEd25519Condition(
|
||
|
publicKey: string,
|
||
|
json = true
|
||
|
): Ed25519Sha256JSONCondition;
|
||
|
|
||
|
static makeEd25519Condition(publicKey: string, json = false): Ed25519Sha256;
|
||
|
|
||
|
// static makeEd25519Condition(publicKey: string): Ed25519Sha256JSONCondition;
|
||
|
|
||
|
static makeEd25519Condition(
|
||
|
publicKey: string,
|
||
|
json?: boolean
|
||
|
): Ed25519Sha256 | Ed25519Sha256JSONCondition;
|
||
|
|
||
|
static makeSha256Condition(
|
||
|
preimage: string,
|
||
|
json = true
|
||
|
): PreimageSha256JSONCondition;
|
||
|
|
||
|
static makeSha256Condition(preimage: string, json = false): PreimageSha256;
|
||
|
|
||
|
// static makeSha256Condition(preimage: string): PreimageSha256JSONCondition;
|
||
|
|
||
|
static makeSha256Condition(
|
||
|
preimage: string,
|
||
|
json?: boolean
|
||
|
): PreimageSha256 | PreimageSha256JSONCondition;
|
||
|
|
||
|
static makeThresholdCondition(
|
||
|
threshold: number,
|
||
|
subconditions: (string | Fulfillment)[],
|
||
|
json = true
|
||
|
): ThresholdSha256JSONCondition;
|
||
|
|
||
|
static makeThresholdCondition(
|
||
|
threshold: number,
|
||
|
subconditions: (string | Fulfillment)[],
|
||
|
json = false
|
||
|
): ThresholdSha256;
|
||
|
|
||
|
// static makeThresholdCondition(
|
||
|
// threshold: number,
|
||
|
// subconditions: (string | Fulfillment)[]
|
||
|
// ): ThresholdSha256JSONCondition;
|
||
|
|
||
|
static makeThresholdCondition(
|
||
|
threshold: number,
|
||
|
subconditions: (string | Fulfillment)[],
|
||
|
json?: boolean
|
||
|
): ThresholdSha256 | ThresholdSha256JSONCondition;
|
||
|
|
||
|
static makeInputTemplate(
|
||
|
publicKeys: string[],
|
||
|
fulfills?: TransactionInput['fulfills'],
|
||
|
fulfillment?: TransactionInput['fulfillment']
|
||
|
): TransactionInput;
|
||
|
|
||
|
static makeOutput(
|
||
|
condition: JSONCondition,
|
||
|
amount: string
|
||
|
): TransactionOutput;
|
||
|
|
||
|
static makeTransactionTemplate(): TxTemplate;
|
||
|
|
||
|
static makeTransaction<
|
||
|
O extends keyof TransactionOperations,
|
||
|
A = Record<string, any>,
|
||
|
M = Record<string, any>
|
||
|
>(
|
||
|
operation: O,
|
||
|
asset: A,
|
||
|
metadata: M,
|
||
|
outputs: TransactionOutput[],
|
||
|
inputs: TransactionInput[]
|
||
|
): TransactionCommon<O, A, M>;
|
||
|
|
||
|
static makeCreateTransaction<
|
||
|
A = Record<string, any>,
|
||
|
M = Record<string, any>
|
||
|
>(
|
||
|
asset: A,
|
||
|
metadata: M,
|
||
|
outputs: TransactionOutput[],
|
||
|
...issuers: string[]
|
||
|
): CreateTransaction<A, M>;
|
||
|
|
||
|
static makeTransferTransaction<M = Record<string, any>>(
|
||
|
unspentOutputs: TransactionOutput[],
|
||
|
outputs: TransactionOutput[],
|
||
|
metadata: M
|
||
|
): TransferTransaction<M>;
|
||
|
|
||
|
static signTransaction<O = TransactionOperations.CREATE>(
|
||
|
transaction: TransactionCommon<O>,
|
||
|
...privateKeys: string[]
|
||
|
): TransactionCommonSigned<O>;
|
||
|
|
||
|
static delegateSignTransaction<O = TransactionOperations.CREATE>(
|
||
|
transaction: TransactionCommon<O>,
|
||
|
signFn: DelegateSignFunction
|
||
|
): TransactionCommonSigned<O>;
|
||
|
}
|