1
0
mirror of https://github.com/bigchaindb/js-bigchaindb-driver.git synced 2024-06-17 10:03:19 +02:00
js-bigchaindb-driver/types/utils/ccJsonify.d.ts

53 lines
1.5 KiB
TypeScript
Raw Normal View History

2021-03-10 08:48:34 +01:00
// Copyright BigchainDB GmbH and BigchainDB contributors
// SPDX-License-Identifier: (Apache-2.0 AND CC-BY-4.0)
// Code is Apache-2.0 and docs are CC-BY-4.0
import type { Condition, Fulfillment } from 'crypto-conditions';
import type { TypeId } from 'crypto-conditions/types/types';
interface BaseJSONCondition {
details: {
type: TypeName;
hash?: string;
max_fulfillment_length?: number;
type?: 'fulfillement' | 'condition';
[key: string]: any;
};
uri: string;
}
2021-03-10 11:03:53 +01:00
export interface Ed25519Sha256JSONCondition extends BaseJSONCondition {
2021-03-10 08:48:34 +01:00
details: { type: TypeName.Ed25519Sha256; publicKey?: string };
}
2021-03-10 11:03:53 +01:00
export interface PreimageSha256JSONCondition extends BaseJSONCondition {
2021-03-10 08:48:34 +01:00
details: {
type: TypeName.PreimageSha256;
type_id: 0;
bitmask: 3;
preimage?: string;
type?: 'fulfillement';
};
}
2021-03-10 11:03:53 +01:00
export interface ThresholdSha256JSONCondition extends BaseJSONCondition {
2021-03-10 08:48:34 +01:00
details: {
type: TypeName.ThresholdSha256;
subConditions: (Ed25519Sha256JSONCondition | PreimageSha256JSONCondition)[];
};
}
2021-03-10 11:03:53 +01:00
export type JSONConditionUnion =
| PreimageSha256JSONCondition
| Ed25519Sha256JSONCondition
| ThresholdSha256JSONCondition;
export interface JSONConditions {
2021-03-10 08:48:34 +01:00
[TypeId.ThresholdSha256]: ThresholdSha256JSONCondition;
[TypeId.PreimageSha256]: PreimageSha256JSONCondition;
[TypeId.Ed25519Sha256]: Ed25519Sha256JSONCondition;
}
export default function ccJsonify<T = TypeId.Ed25519Sha256>(
fulfillment: Fulfillment | Condition
2021-03-10 11:03:53 +01:00
): JSONConditions[T];