-
Notifications
You must be signed in to change notification settings - Fork 55
/
types.ts
103 lines (90 loc) · 2.5 KB
/
types.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
import { Cardano } from '@cardano-sdk/core';
import { TxInternals } from '../Transaction';
export type HexBlob = Cardano.util.OpaqueString<'HexBlob'>;
export const HexBlob = (target: string): HexBlob => Cardano.util.typedHex(target);
export interface SignBlobResult {
publicKey: Cardano.Ed25519PublicKey;
signature: Cardano.Ed25519Signature;
}
export enum KeyAgentType {
InMemory = 'InMemory'
}
export enum KeyType {
External = 0,
Internal = 1,
Stake = 2
}
export interface AccountKeyDerivationPath {
type: KeyType;
index: number;
}
/** Internal = change address & External = receipt address */
export enum AddressType {
/**
* Change address
*/
Internal = 1,
/**
* Receipt address
*/
External = 0
}
export interface AccountAddressDerivationPath {
type: AddressType;
index: number;
}
export interface GroupedAddress {
type: AddressType;
index: number;
networkId: Cardano.NetworkId;
accountIndex: number;
address: Cardano.Address;
rewardAccount: Cardano.RewardAccount;
}
/**
* number[] is used by InMemoryKeyAgent
*/
export type AgentSpecificData = number[] | null;
export interface SerializableKeyAgentDataBase {
networkId: Cardano.NetworkId;
accountIndex: number;
}
export interface SerializableInMemoryKeyAgentData extends SerializableKeyAgentDataBase {
__typename: KeyAgentType.InMemory;
encryptedRootPrivateKeyBytes: number[];
}
export type SerializableKeyAgentData = SerializableInMemoryKeyAgentData;
// TODO: utility to cache password for specified duration
/**
* @returns password used to decrypt root private key
*/
export type GetPassword = (noCache?: true) => Promise<Uint8Array>;
export interface KeyAgent {
get networkId(): Cardano.NetworkId;
get accountIndex(): number;
get serializableData(): SerializableKeyAgentData;
/**
* @throws AuthenticationError
*/
getExtendedAccountPublicKey(): Promise<Cardano.Bip32PublicKey>;
/**
* @throws AuthenticationError
*/
signBlob(derivationPath: AccountKeyDerivationPath, blob: HexBlob): Promise<SignBlobResult>;
/**
* @throws AuthenticationError
*/
signTransaction(txInternals: TxInternals): Promise<Cardano.Signatures>;
/**
* @throws AuthenticationError
*/
derivePublicKey(derivationPath: AccountKeyDerivationPath): Promise<Cardano.Ed25519PublicKey>;
/**
* @throws AuthenticationError
*/
deriveAddress(derivationPath: AccountAddressDerivationPath): Promise<GroupedAddress>;
/**
* @throws AuthenticationError
*/
exportRootPrivateKey(): Promise<Cardano.Bip32PrivateKey>;
}