@keplr-wallet/chain-validator 0.11.18-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintignore +2 -0
- package/.prettierignore +2 -0
- package/LICENSE +203 -0
- package/build/basic.d.ts +2 -0
- package/build/basic.js +22 -0
- package/build/basic.js.map +1 -0
- package/build/connection.d.ts +2 -0
- package/build/connection.js +95 -0
- package/build/connection.js.map +1 -0
- package/build/feature.d.ts +30 -0
- package/build/feature.js +162 -0
- package/build/feature.js.map +1 -0
- package/build/feature.spec.d.ts +1 -0
- package/build/feature.spec.js +355 -0
- package/build/feature.spec.js.map +1 -0
- package/build/index.d.ts +4 -0
- package/build/index.js +17 -0
- package/build/index.js.map +1 -0
- package/build/schema.d.ts +17 -0
- package/build/schema.js +157 -0
- package/build/schema.js.map +1 -0
- package/build/schema.spec.d.ts +1 -0
- package/build/schema.spec.js +918 -0
- package/build/schema.spec.js.map +1 -0
- package/jest.config.js +5 -0
- package/package.json +27 -0
- package/src/basic.ts +11 -0
- package/src/connection.ts +125 -0
- package/src/feature.spec.ts +429 -0
- package/src/feature.ts +198 -0
- package/src/index.ts +4 -0
- package/src/schema.spec.ts +1172 -0
- package/src/schema.ts +205 -0
- package/tsconfig.json +13 -0
package/src/schema.ts
ADDED
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
import {
|
|
2
|
+
AppCurrency,
|
|
3
|
+
Bech32Config,
|
|
4
|
+
BIP44,
|
|
5
|
+
ChainInfo,
|
|
6
|
+
Currency,
|
|
7
|
+
CW20Currency,
|
|
8
|
+
FeeCurrency,
|
|
9
|
+
Secret20Currency,
|
|
10
|
+
WithGasPriceStep,
|
|
11
|
+
} from "@keplr-wallet/types";
|
|
12
|
+
import { SupportedChainFeatures } from "./feature";
|
|
13
|
+
|
|
14
|
+
import Joi, { ObjectSchema } from "joi";
|
|
15
|
+
|
|
16
|
+
export const CurrencySchema = Joi.object<Currency>({
|
|
17
|
+
coinDenom: Joi.string().required(),
|
|
18
|
+
coinMinimalDenom: Joi.string().required(),
|
|
19
|
+
coinDecimals: Joi.number().integer().min(0).max(18).required(),
|
|
20
|
+
coinGeckoId: Joi.string(),
|
|
21
|
+
coinImageUrl: Joi.string().uri(),
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
export const CW20CurrencySchema = (CurrencySchema as ObjectSchema<CW20Currency>)
|
|
25
|
+
.keys({
|
|
26
|
+
type: Joi.string().equal("cw20").required(),
|
|
27
|
+
contractAddress: Joi.string().required(),
|
|
28
|
+
})
|
|
29
|
+
.custom((value: CW20Currency) => {
|
|
30
|
+
if (
|
|
31
|
+
value.coinMinimalDenom.startsWith(
|
|
32
|
+
`${value.type}:${value.contractAddress}:`
|
|
33
|
+
)
|
|
34
|
+
) {
|
|
35
|
+
return value;
|
|
36
|
+
} else {
|
|
37
|
+
return {
|
|
38
|
+
...value,
|
|
39
|
+
coinMinimalDenom:
|
|
40
|
+
`${value.type}:${value.contractAddress}:` + value.coinMinimalDenom,
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
export const Secret20CurrencySchema = (CurrencySchema as ObjectSchema<Secret20Currency>)
|
|
46
|
+
.keys({
|
|
47
|
+
type: Joi.string().equal("secret20").required(),
|
|
48
|
+
contractAddress: Joi.string().required(),
|
|
49
|
+
viewingKey: Joi.string().required(),
|
|
50
|
+
})
|
|
51
|
+
.custom((value: Secret20Currency) => {
|
|
52
|
+
if (
|
|
53
|
+
value.coinMinimalDenom.startsWith(
|
|
54
|
+
`${value.type}:${value.contractAddress}:`
|
|
55
|
+
)
|
|
56
|
+
) {
|
|
57
|
+
return value;
|
|
58
|
+
} else {
|
|
59
|
+
return {
|
|
60
|
+
...value,
|
|
61
|
+
coinMinimalDenom:
|
|
62
|
+
`${value.type}:${value.contractAddress}:` + value.coinMinimalDenom,
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
const GasPriceStepSchema = Joi.object<{
|
|
68
|
+
readonly low: number;
|
|
69
|
+
readonly average: number;
|
|
70
|
+
readonly high: number;
|
|
71
|
+
}>({
|
|
72
|
+
low: Joi.number().required(),
|
|
73
|
+
average: Joi.number().required(),
|
|
74
|
+
high: Joi.number().required(),
|
|
75
|
+
}).custom((value) => {
|
|
76
|
+
if (value.low > value.average) {
|
|
77
|
+
throw new Error("Low gas price step can not be greater than average");
|
|
78
|
+
}
|
|
79
|
+
if (value.average > value.high) {
|
|
80
|
+
throw new Error("Average gas price step can not be greater than high");
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
return value;
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
export const FeeCurrencySchema = (CurrencySchema as Joi.ObjectSchema<
|
|
87
|
+
WithGasPriceStep<Currency>
|
|
88
|
+
>).keys({
|
|
89
|
+
gasPriceStep: GasPriceStepSchema,
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
export const Bech32ConfigSchema = Joi.object<Bech32Config>({
|
|
93
|
+
bech32PrefixAccAddr: Joi.string().required(),
|
|
94
|
+
bech32PrefixAccPub: Joi.string().required(),
|
|
95
|
+
bech32PrefixValAddr: Joi.string().required(),
|
|
96
|
+
bech32PrefixValPub: Joi.string().required(),
|
|
97
|
+
bech32PrefixConsAddr: Joi.string().required(),
|
|
98
|
+
bech32PrefixConsPub: Joi.string().required(),
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
export const SuggestingBIP44Schema = Joi.object<{ coinType: number }>({
|
|
102
|
+
coinType: Joi.number().integer().min(0).required(),
|
|
103
|
+
// Alow the any keys for compatibility of cosmosJS's BIP44 (for legacy).
|
|
104
|
+
}).unknown(true);
|
|
105
|
+
|
|
106
|
+
export const ChainInfoSchema = Joi.object<ChainInfo>({
|
|
107
|
+
rpc: Joi.string()
|
|
108
|
+
.uri()
|
|
109
|
+
.custom((value: string) => {
|
|
110
|
+
if (value.includes("?")) {
|
|
111
|
+
throw new Error("rpc should not have query string");
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
return value;
|
|
115
|
+
})
|
|
116
|
+
.required(),
|
|
117
|
+
// TODO: Handle rpc config.
|
|
118
|
+
rest: Joi.string()
|
|
119
|
+
.uri()
|
|
120
|
+
.custom((value: string) => {
|
|
121
|
+
if (value.includes("?")) {
|
|
122
|
+
throw new Error("rest should not have query string");
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
return value;
|
|
126
|
+
})
|
|
127
|
+
.required(),
|
|
128
|
+
// TODO: Handle rest config.
|
|
129
|
+
chainId: Joi.string().required().min(1).max(30),
|
|
130
|
+
chainName: Joi.string().required().min(1).max(30),
|
|
131
|
+
stakeCurrency: CurrencySchema.required(),
|
|
132
|
+
walletUrl: Joi.string().uri(),
|
|
133
|
+
walletUrlForStaking: Joi.string().uri(),
|
|
134
|
+
bip44: SuggestingBIP44Schema.required(),
|
|
135
|
+
alternativeBIP44s: Joi.array()
|
|
136
|
+
.items(SuggestingBIP44Schema)
|
|
137
|
+
.custom((values: BIP44[]) => {
|
|
138
|
+
const dups: { [coinType: number]: boolean | undefined } = {};
|
|
139
|
+
|
|
140
|
+
for (const val of values) {
|
|
141
|
+
if (dups[val.coinType]) {
|
|
142
|
+
throw new Error(`coin type ${val.coinType} is duplicated`);
|
|
143
|
+
}
|
|
144
|
+
dups[val.coinType] = true;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
return values;
|
|
148
|
+
}),
|
|
149
|
+
bech32Config: Bech32ConfigSchema.required(),
|
|
150
|
+
currencies: Joi.array()
|
|
151
|
+
.min(1)
|
|
152
|
+
.items(CurrencySchema, CW20CurrencySchema, Secret20CurrencySchema)
|
|
153
|
+
.custom((values: AppCurrency[]) => {
|
|
154
|
+
const dups: { [denom: string]: boolean | undefined } = {};
|
|
155
|
+
|
|
156
|
+
for (const val of values) {
|
|
157
|
+
if (dups[val.coinMinimalDenom]) {
|
|
158
|
+
throw new Error(`${val.coinMinimalDenom} is duplicated`);
|
|
159
|
+
}
|
|
160
|
+
dups[val.coinMinimalDenom] = true;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
return values;
|
|
164
|
+
})
|
|
165
|
+
.required(),
|
|
166
|
+
feeCurrencies: Joi.array()
|
|
167
|
+
.min(1)
|
|
168
|
+
.items(FeeCurrencySchema)
|
|
169
|
+
.custom((values: FeeCurrency[]) => {
|
|
170
|
+
const dups: { [denom: string]: boolean | undefined } = {};
|
|
171
|
+
|
|
172
|
+
for (const val of values) {
|
|
173
|
+
if (dups[val.coinMinimalDenom]) {
|
|
174
|
+
throw new Error(`${val.coinMinimalDenom} is duplicated`);
|
|
175
|
+
}
|
|
176
|
+
dups[val.coinMinimalDenom] = true;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
return values;
|
|
180
|
+
})
|
|
181
|
+
.required(),
|
|
182
|
+
coinType: Joi.number().integer(),
|
|
183
|
+
beta: Joi.boolean(),
|
|
184
|
+
features: Joi.array()
|
|
185
|
+
.items(Joi.string().valid(...SupportedChainFeatures))
|
|
186
|
+
.unique()
|
|
187
|
+
.custom((value: string[]) => {
|
|
188
|
+
if (value.indexOf("cosmwasm") >= 0 && value.indexOf("secretwasm") >= 0) {
|
|
189
|
+
throw new Error("cosmwasm and secretwasm are not compatible");
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
return value;
|
|
193
|
+
}),
|
|
194
|
+
chainSymbolImageUrl: Joi.string().uri(),
|
|
195
|
+
}).custom((value: ChainInfo) => {
|
|
196
|
+
if (
|
|
197
|
+
value.alternativeBIP44s?.find(
|
|
198
|
+
(bip44) => bip44.coinType === value.bip44.coinType
|
|
199
|
+
)
|
|
200
|
+
) {
|
|
201
|
+
throw new Error(`coin type ${value.bip44.coinType} is duplicated`);
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
return value;
|
|
205
|
+
});
|