@vechain/connex
Version:
Standard interface to connect DApp with VeChain and user
73 lines (72 loc) • 2.26 kB
TypeScript
/// <reference types="@vechain/connex-types" />
export declare type NewSignerFunc = (genesisId: string) => Promise<Connex.Signer>;
export declare const createSync2: NewSignerFunc;
export declare const createSync: NewSignerFunc;
export declare interface Connex1 {
readonly vendor: Connex1.Vendor;
readonly thor: Connex1.Thor;
}
export declare namespace Connex1 {
interface Thor {
readonly genesis: {
id: string;
};
}
namespace Thor {
type Clause = {
to: string | null;
value: string | number;
data?: string;
};
}
interface Vendor {
sign<T extends 'tx' | 'cert'>(kind: T): Vendor.SigningService<T>;
owned(addr: string): Promise<boolean>;
}
namespace Vendor {
interface TxSigningService {
signer(addr: string): this;
gas(gas: number): this;
dependsOn(txid: string): this;
link(url: string): this;
comment(text: string): this;
delegate(handler: DelegationHandler): this;
request(msg: TxMessage): Promise<TxResponse>;
}
interface CertSigningService {
signer(addr: string): this;
link(url: string): this;
request(msg: CertMessage): Promise<CertResponse>;
}
type SigningService<T extends 'tx' | 'cert'> = T extends 'tx' ? TxSigningService : T extends 'cert' ? CertSigningService : never;
type TxMessage = Array<Thor.Clause & {
comment?: string;
abi?: object;
}>;
type CertMessage = {
purpose: 'identification' | 'agreement';
payload: {
type: 'text';
content: string;
};
};
type TxResponse = {
txid: string;
signer: string;
};
type CertResponse = {
annex: {
domain: string;
timestamp: number;
signer: string;
};
signature: string;
};
type DelegationHandler = (unsignedTx: {
raw: string;
origin: string;
}) => Promise<{
signature: string;
}>;
}
}