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
|
|
|
|
|
2021-03-10 13:20:32 +01:00
|
|
|
import type {
|
|
|
|
Condition,
|
|
|
|
Ed25519Sha256,
|
|
|
|
PreimageSha256,
|
|
|
|
ThresholdSha256,
|
|
|
|
} from 'crypto-conditions';
|
2021-03-11 13:05:14 +01:00
|
|
|
import type { TypeId, TypeName } from 'crypto-conditions/types/types';
|
2021-03-10 08:48:34 +01:00
|
|
|
|
|
|
|
interface BaseJSONCondition {
|
|
|
|
details: {
|
|
|
|
[key: string]: any;
|
|
|
|
};
|
|
|
|
uri: string;
|
|
|
|
}
|
|
|
|
|
2021-03-10 13:20:32 +01:00
|
|
|
export interface JSONCondition extends BaseJSONCondition {
|
|
|
|
details: {
|
|
|
|
type_id: TypeId;
|
|
|
|
bitmask: number;
|
|
|
|
type: 'condition';
|
|
|
|
hash: string;
|
|
|
|
max_fulfillment_length: number;
|
|
|
|
};
|
2021-03-10 08:48:34 +01:00
|
|
|
}
|
2021-03-10 13:20:32 +01:00
|
|
|
|
2021-03-10 11:03:53 +01:00
|
|
|
export interface PreimageSha256JSONCondition extends BaseJSONCondition {
|
2021-03-10 08:48:34 +01:00
|
|
|
details: {
|
2021-03-10 13:20:32 +01:00
|
|
|
type_id: TypeId.PreimageSha256;
|
2021-03-10 08:48:34 +01:00
|
|
|
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 13:20:32 +01:00
|
|
|
export interface Ed25519Sha256JSONCondition extends BaseJSONCondition {
|
|
|
|
details: { type: TypeName.Ed25519Sha256; publicKey?: string };
|
|
|
|
}
|
|
|
|
|
2021-03-10 11:03:53 +01:00
|
|
|
export type JSONConditionUnion =
|
2021-03-10 13:20:32 +01:00
|
|
|
| JSONCondition
|
2021-03-10 11:03:53 +01:00
|
|
|
| PreimageSha256JSONCondition
|
2021-03-10 13:20:32 +01:00
|
|
|
| ThresholdSha256JSONCondition
|
|
|
|
| Ed25519Sha256JSONCondition;
|
2021-03-10 11:03:53 +01:00
|
|
|
|
2021-03-10 13:20:32 +01:00
|
|
|
declare function ccJsonify(
|
|
|
|
fulfillment: PreimageSha256
|
|
|
|
): PreimageSha256JSONCondition;
|
|
|
|
|
|
|
|
declare function ccJsonify(
|
|
|
|
fulfillment: ThresholdSha256
|
|
|
|
): ThresholdSha256JSONCondition;
|
|
|
|
|
|
|
|
declare function ccJsonify(
|
|
|
|
fulfillment: Ed25519Sha256
|
|
|
|
): Ed25519Sha256JSONCondition;
|
|
|
|
|
|
|
|
declare function ccJsonify(fulfillment: Condition): JSONCondition;
|
2021-03-10 08:48:34 +01:00
|
|
|
|
2021-03-10 13:20:32 +01:00
|
|
|
export default ccJsonify;
|