/
publicTypes.ts
185 lines (168 loc) · 3.92 KB
/
publicTypes.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
import {
CnsSupportedNetwork,
EventFilter,
RequestArguments,
RpcProviderLogEntry,
TransactionRequest,
ZnsSupportedNetwork,
} from '.';
export type CnsSupportedNetworks = typeof CnsSupportedNetwork.type;
export type ZnsSupportedNetworks = typeof ZnsSupportedNetwork.type;
export type Api = {api: true; url?: string};
type NamingServiceSource = {url?: string} | {provider?: Provider};
export type CnsSource = NamingServiceSource & {
network: CnsSupportedNetworks;
proxyReaderAddress?: string;
};
export type ZnsSource = NamingServiceSource & {
network: ZnsSupportedNetworks;
registryAddress?: string;
};
export type SourceConfig = {
cns?: CnsSource | Api;
zns?: ZnsSource | Api;
};
export enum NamingServiceName {
CNS = 'CNS',
ZNS = 'ZNS',
}
export type ResolutionMethod = NamingServiceName | 'UDAPI';
export type AutoNetworkConfigs = {
cns?: {url: string} | {provider: Provider};
};
/**
* 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 = {
addresses: {
[key: string]: string;
};
meta: {
owner: string | null;
type: string; // available domain
namehash: string;
resolver: string;
ttl: number;
};
records: {
[key: string]: string;
};
};
export interface Web3Version0Provider {
sendAsync: ProviderMethod;
}
export interface Web3Version1Provider {
send: ProviderMethod;
}
/**
* @see https://eips.ethereum.org/EIPS/eip-1193
*/
export interface Provider {
request: (request: RequestArguments) => Promise<unknown>;
}
type ProviderMethod = (
payload: JsonRpcPayload,
callback: (error: Error | null, result?: JsonRpcResponse) => void,
) => void;
export const UnclaimedDomainResponse: ResolutionResponse = {
addresses: {},
meta: {
namehash: '',
resolver: '',
owner: null, // available domain
type: '',
ttl: 0,
},
records: {},
};
/**
* @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;
}
/**
* @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>;
getLogs(filter: EventFilter): Promise<RpcProviderLogEntry[]>;
}
export const UDApiDefaultUrl = 'https://unstoppabledomains.com/api/v1';
export type NamehashOptions = {
readonly format?: 'dec' | 'hex';
readonly prefix?: boolean;
};
export const NamehashOptionsDefault = {format: 'hex', prefix: true} as const;
export enum DnsRecordType {
A = 'A',
AAAA = 'AAAA',
AFSDB = 'AFSDB',
APL = 'APL',
CAA = 'CAA',
CDNSKEY = 'CDNSKEY',
CDS = 'CDS',
CERT = 'CERT',
CNAME = 'CNAME',
CSYNC = 'CSYNC',
DHCID = 'DHCID',
DLV = 'DLV',
DNAME = 'DNAME',
DNSKEY = 'DNSKEY',
DS = 'DS',
EUI48 = 'EUI48',
EUI64 = 'EUI64',
HINFO = 'HINFO',
HIP = 'HIP',
HTTPS = 'HTTPS',
IPSECKEY = 'IPSECKEY',
KEY = 'KEY',
KX = 'KX',
LOC = 'LOC',
MX = 'MX',
NAPTR = 'NAPTR',
NS = 'NS',
NSEC = 'NSEC',
NSEC3 = 'NSEC3',
NSEC3PARAM = 'NSEC3PARAM',
OPENPGPKEY = 'OPENPGPKEY',
PTR = 'PTR',
RP = 'RP',
RRSIG = 'RRSIG',
SIG = 'SIG',
SMIMEA = 'SMIMEA',
SOA = 'SOA',
SRV = 'SRV',
SSHFP = 'SSHFP',
SVCB = 'SVCB',
TA = 'TA',
TKEY = 'TKEY',
TLSA = 'TLSA',
TSIG = 'TSIG',
TXT = 'TXT',
URI = 'URI',
ZONEMD = 'ZONEMD',
}
export interface DnsRecord {
type: DnsRecordType;
TTL: number;
data: string;
}
export type CryptoRecords = Record<string, string>;
export type DomainData = {
owner: string;
resolver: string;
records: CryptoRecords;
};