mirror of
https://github.com/bigchaindb/js-bigchaindb-driver.git
synced 2024-12-27 07:07:50 +01:00
fix: refine Crypoconditions parsers types
Signed-off-by: getlarge <ed@getlarge.eu>
This commit is contained in:
parent
b177ca0de4
commit
af90b97460
33
types/utils/ccJsonLoad.d.ts
vendored
33
types/utils/ccJsonLoad.d.ts
vendored
@ -2,10 +2,31 @@
|
||||
// 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 { JSONCondition } from './ccJsonify';
|
||||
import type {
|
||||
Condition,
|
||||
Ed25519Sha256,
|
||||
PreimageSha256,
|
||||
ThresholdSha256,
|
||||
} from 'crypto-conditions';
|
||||
import type {
|
||||
Ed25519Sha256JSONCondition,
|
||||
JSONCondition,
|
||||
PreimageSha256JSONCondition,
|
||||
ThresholdSha256JSONCondition,
|
||||
} from './ccJsonify';
|
||||
|
||||
// TODO: improve returned type accuracy
|
||||
export default function ccJsonLoad<T = TypeId.Ed25519Sha256>(
|
||||
conditionJson: JSONCondition[T]
|
||||
): Condition | Fulfillment;
|
||||
declare function ccJsonLoad(
|
||||
conditionJson: PreimageSha256JSONCondition
|
||||
): PreimageSha256;
|
||||
|
||||
declare function ccJsonLoad(
|
||||
conditionJson: ThresholdSha256JSONCondition
|
||||
): ThresholdSha256;
|
||||
|
||||
declare function ccJsonLoad(
|
||||
conditionJson: Ed25519Sha256JSONCondition
|
||||
): Ed25519Sha256;
|
||||
|
||||
declare function ccJsonLoad(conditionJson: JSONCondition): Condition;
|
||||
|
||||
export default ccJsonLoad;
|
||||
|
60
types/utils/ccJsonify.d.ts
vendored
60
types/utils/ccJsonify.d.ts
vendored
@ -2,27 +2,34 @@
|
||||
// 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 {
|
||||
Condition,
|
||||
Ed25519Sha256,
|
||||
PreimageSha256,
|
||||
ThresholdSha256,
|
||||
} 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;
|
||||
}
|
||||
|
||||
export interface Ed25519Sha256JSONCondition extends BaseJSONCondition {
|
||||
details: { type: TypeName.Ed25519Sha256; publicKey?: string };
|
||||
export interface JSONCondition extends BaseJSONCondition {
|
||||
details: {
|
||||
type_id: TypeId;
|
||||
bitmask: number;
|
||||
type: 'condition';
|
||||
hash: string;
|
||||
max_fulfillment_length: number;
|
||||
};
|
||||
}
|
||||
|
||||
export interface PreimageSha256JSONCondition extends BaseJSONCondition {
|
||||
details: {
|
||||
type: TypeName.PreimageSha256;
|
||||
type_id: 0;
|
||||
type_id: TypeId.PreimageSha256;
|
||||
bitmask: 3;
|
||||
preimage?: string;
|
||||
type?: 'fulfillement';
|
||||
@ -36,17 +43,28 @@ export interface ThresholdSha256JSONCondition extends BaseJSONCondition {
|
||||
};
|
||||
}
|
||||
|
||||
export type JSONConditionUnion =
|
||||
| PreimageSha256JSONCondition
|
||||
| Ed25519Sha256JSONCondition
|
||||
| ThresholdSha256JSONCondition;
|
||||
|
||||
export interface JSONConditions {
|
||||
[TypeId.ThresholdSha256]: ThresholdSha256JSONCondition;
|
||||
[TypeId.PreimageSha256]: PreimageSha256JSONCondition;
|
||||
[TypeId.Ed25519Sha256]: Ed25519Sha256JSONCondition;
|
||||
export interface Ed25519Sha256JSONCondition extends BaseJSONCondition {
|
||||
details: { type: TypeName.Ed25519Sha256; publicKey?: string };
|
||||
}
|
||||
|
||||
export default function ccJsonify<T = TypeId.Ed25519Sha256>(
|
||||
fulfillment: Fulfillment | Condition
|
||||
): JSONConditions[T];
|
||||
export type JSONConditionUnion =
|
||||
| JSONCondition
|
||||
| PreimageSha256JSONCondition
|
||||
| ThresholdSha256JSONCondition
|
||||
| Ed25519Sha256JSONCondition;
|
||||
|
||||
declare function ccJsonify(
|
||||
fulfillment: PreimageSha256
|
||||
): PreimageSha256JSONCondition;
|
||||
|
||||
declare function ccJsonify(
|
||||
fulfillment: ThresholdSha256
|
||||
): ThresholdSha256JSONCondition;
|
||||
|
||||
declare function ccJsonify(
|
||||
fulfillment: Ed25519Sha256
|
||||
): Ed25519Sha256JSONCondition;
|
||||
|
||||
declare function ccJsonify(fulfillment: Condition): JSONCondition;
|
||||
|
||||
export default ccJsonify;
|
||||
|
Loading…
Reference in New Issue
Block a user