/
types.ts
205 lines (174 loc) · 4.34 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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
export type Dictionary<T> = { [k: string]: T };
/**
* SourceDefinition object
* @typedef {Object} SourceDefinition
* @property {string} [url] - main blockchain api url
* @property {string | number} [network] - blockchain network
*/
export interface SourceDefinition {
url?: string;
network?: string | number;
registry?: string;
provider?: Provider;
}
/**
* NamingServiceSource
* just an alias
* @typedef {string | boolean | SourceDefinition}
*/
export type NamingServiceSource = string | boolean | SourceDefinition;
export enum NamingServiceName {
ENS = 'ENS',
CNS = 'CNS',
ZNS = 'ZNS',
}
export type ResolutionMethod = NamingServiceName | 'UDAPI';
/** @internal */
export type EnsNetworkIdMap = {
[key: number]: string;
};
/** @internal */
export interface BlockhanNetworkUrlMap {
[key: string]: string;
}
/** @internal */
export interface RegistryMap {
[key: string]: string;
}
/**
* ResolutionResulution
* @typedef ResolutionResponse
* @property {Object} addresses - Resolution addresses for various currency addresses attached to the domain
* @property {Object} meta - meta information about the owner of the domain
*/
export type ResolutionResponse = {
ipfs?: {
html?: string;
redirect_domain?: string;
};
whois?: {
email?: string;
for_sale?: boolean;
};
gundb?: {
username?: string;
public_key?: string;
};
addresses: {
[key: string]: string;
};
meta: {
owner: string | null;
type: string; //available domain
ttl: number;
};
};
/** @internal */
export type NetworkIdMap = {
[key: number]: string;
};
export const UDApiDefaultUrl = 'https://unstoppabledomains.com/api/v1';
/**
* Main configurational object for Resolution instance
*/
export type Blockchain = {
ens?: NamingServiceSource;
zns?: NamingServiceSource;
cns?: NamingServiceSource;
web3Provider?: Provider;
};
export type API = {
url: string;
};
export type ProviderParams = unknown[] | object;
export interface RequestArguments {
method: string;
params?: ProviderParams;
}
/**
* @see https://eips.ethereum.org/EIPS/eip-1193
*/
export interface Provider {
request: (request: RequestArguments) => Promise<unknown>;
}
/**
* @see https://github.com/ethereum/web3.js/blob/1.x/packages/web3-core-helpers/types/index.d.ts#L216
*/
export interface JsonRpcPayload {
jsonrpc: string;
method: string;
params: any[];
id?: string | number;
}
export interface JsonRpcResponse {
jsonrpc: string;
id: number;
result?: any;
error?: string;
}
type ProviderMethod = (
payload: JsonRpcPayload,
callback: (error: Error | null, result?: JsonRpcResponse) => void,
) => void;
export type TransactionRequest = {
to?: unknown,
from?: unknown,
nonce?: unknown,
gasLimit?: unknown,
gasPrice?: unknown,
data?: unknown,
value?: unknown,
chainId?: unknown,
}
/**
* @see https://github.com/ethers-io/ethers.js/blob/v5.0.4/packages/abstract-provider/src.ts/index.ts#L224
*/
export interface EthersProvider {
call(transaction: TransactionRequest, blockTag?: never): Promise<string>;
}
export interface Web3Version0Provider {
sendAsync: ProviderMethod;
}
export interface Web3Version1Provider {
send: ProviderMethod;
}
export const DefaultAPI: API = {
url: UDApiDefaultUrl,
};
/**
* Default structure of ZnsResolution records
* @typedef {object} ZnsResolution
*/
export type ZnsResolution = {
crypto?: Dictionary<{ address?: string; [key: string]: any }>;
ttl?: string;
[key: string]: any;
};
export type Bip44Constants = [number, string, string];
export type owner = string;
export type ttl = string;
export type nodeHash = string;
export const NullAddress = '0x0000000000000000000000000000000000000000';
/** @internal */
export enum NullAddresses {
'0x',
'0x0000000000000000000000000000000000000000',
'0x0000000000000000000000000000000000000000000000000000000000000000',
}
export function isNullAddress(key: string | null | undefined): key is undefined | null {
if (!key) return true;
return Object.values(NullAddresses).includes(key);
}
export const EthCoinIndex = 60;
export const UnclaimedDomainResponse: ResolutionResponse = {
addresses: {},
meta: {
owner: null, //available domain
type: '',
ttl: 0,
},
};
/**
* @deprecated Use UnclaimedDomainResponse instead (deprecated since 0.3.4)
*/
export const UNCLAIMED_DOMAIN_RESPONSE = UnclaimedDomainResponse;