@ledgerhq/revault-api 1.20.0
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/LICENSE.md +202 -0
- package/README.md +32 -0
- package/lib/app-types-Cvdd2De7.d.mts +40156 -0
- package/lib/fakes.d.mts +4628 -0
- package/lib/fakes.mjs +2097 -0
- package/lib/fakes.mjs.map +1 -0
- package/lib/index.d.mts +22332 -0
- package/lib/index.mjs +3 -0
- package/lib/index.mjs.map +1 -0
- package/package.json +119 -0
package/lib/fakes.mjs
ADDED
|
@@ -0,0 +1,2097 @@
|
|
|
1
|
+
import { faker } from '@faker-js/faker';
|
|
2
|
+
import z5, { z } from 'zod';
|
|
3
|
+
import { ChallengeType, PsdModel, AccountType, AccountGovernanceType, ActivationStatus, WhitelistType, PolicyType, UserDeviceType, AdminPermission, RequestType, RequestReviewStatus, RequestState, GateAccountType } from '@prisma/client';
|
|
4
|
+
import 'axios';
|
|
5
|
+
import invariant from 'invariant';
|
|
6
|
+
import { omit, times } from 'lodash';
|
|
7
|
+
|
|
8
|
+
// src/__fakes__/responses.ts
|
|
9
|
+
|
|
10
|
+
// src/errors.ts
|
|
11
|
+
var ValidationError = class extends Error {
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
// src/sync-utils.ts
|
|
15
|
+
var GATE_SYNC_ID_PREFIX = "gate://";
|
|
16
|
+
var buildGateSyncId = (workspaceName, gateType, gateId) => {
|
|
17
|
+
if (gateId <= 0) {
|
|
18
|
+
throw new ValidationError(`Invalid gate ID: ${gateId}`);
|
|
19
|
+
}
|
|
20
|
+
return `${GATE_SYNC_ID_PREFIX}${workspaceName}/${gateType}/${gateId}`;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
// src/utils.ts
|
|
24
|
+
var ensureNonEmptyArray = (values, message) => {
|
|
25
|
+
invariant(
|
|
26
|
+
values.length > 0,
|
|
27
|
+
`Expected non-empty array but got one with length ${values.length}`
|
|
28
|
+
);
|
|
29
|
+
return values;
|
|
30
|
+
};
|
|
31
|
+
function unreachable(value) {
|
|
32
|
+
throw new Error(`Un-covered: ${value}`);
|
|
33
|
+
}
|
|
34
|
+
var zHsmObjectId = z.string().regex(/^[\w-]+$/).min(1);
|
|
35
|
+
var zHexString = z.string().regex(/^[0-9a-fA-F]+$/);
|
|
36
|
+
var zPubKey = zHexString.describe("Public key");
|
|
37
|
+
var zHsmCertificate = z.object({
|
|
38
|
+
codeHash: z.string().base64().describe("Hash of the executable that generated this certificate"),
|
|
39
|
+
attestationPub: z.string().base64().describe("Attestation public key"),
|
|
40
|
+
certificate: z.string().base64().describe("Certificate bytes"),
|
|
41
|
+
signature: z.string().base64().describe("Certificate signature")
|
|
42
|
+
});
|
|
43
|
+
var zBlob = z.string();
|
|
44
|
+
var zPsdChallenge = z.object({
|
|
45
|
+
challengeType: z.literal(ChallengeType.PSD),
|
|
46
|
+
wActions: z.array(z.string()).describe("Wrapped blobs that describe the screens to display"),
|
|
47
|
+
handshake: z.string().describe("Handshake for the HSM <-> PSD communication"),
|
|
48
|
+
handshakeAttestation: zHsmCertificate.describe(
|
|
49
|
+
"Handshake attestation to verify secure channel between HSM & PSD"
|
|
50
|
+
),
|
|
51
|
+
partitionId: z.string().describe("HSM partition id (maybe not useful)")
|
|
52
|
+
});
|
|
53
|
+
var zApiChallenge = z.object({
|
|
54
|
+
challengeType: z.literal(ChallengeType.API),
|
|
55
|
+
payload: z.object({
|
|
56
|
+
approve: z.string().describe("JSON payload to sign (as JWS) to approve"),
|
|
57
|
+
reject: z.string().describe("JSON payload to sign (as JWS) to reject")
|
|
58
|
+
}).describe("JSON payload to approve and to reject")
|
|
59
|
+
});
|
|
60
|
+
var zUserChallenge = z.discriminatedUnion("challengeType", [
|
|
61
|
+
zPsdChallenge.describe("Necessary data to approve on a PSD"),
|
|
62
|
+
zApiChallenge.describe("Necessary data for approval by an API user")
|
|
63
|
+
]);
|
|
64
|
+
var zHsmChallengeGroup = z.record(zPubKey, zUserChallenge);
|
|
65
|
+
var zHsmChallengeSteps = z.array(zHsmChallengeGroup);
|
|
66
|
+
var zPsdSignature = z.string().min(1).describe("Signature from PSD");
|
|
67
|
+
var zApiSignature = z.string().min(1).describe("Signature from API (JWS)");
|
|
68
|
+
var zUserApproval = z.discriminatedUnion("challengeType", [
|
|
69
|
+
z.object({
|
|
70
|
+
challengeType: z.literal(ChallengeType.PSD),
|
|
71
|
+
signature: zPsdSignature
|
|
72
|
+
}),
|
|
73
|
+
z.object({
|
|
74
|
+
challengeType: z.literal(ChallengeType.API),
|
|
75
|
+
signature: zApiSignature
|
|
76
|
+
})
|
|
77
|
+
]);
|
|
78
|
+
var zHsmApprovalGroup = z.record(zPubKey, zUserApproval);
|
|
79
|
+
z.array(zHsmApprovalGroup);
|
|
80
|
+
z.object({
|
|
81
|
+
stageName: z.string(),
|
|
82
|
+
steps: zHsmChallengeSteps
|
|
83
|
+
});
|
|
84
|
+
var zUserRegistrationDeviceData = z.object({
|
|
85
|
+
name: z.string().describe("Name of the user to register"),
|
|
86
|
+
psdModel: z.nativeEnum(PsdModel).describe("Device model"),
|
|
87
|
+
pubKey: zPubKey.describe("Device public key"),
|
|
88
|
+
confidentialityKey: zPubKey.describe("TODO describe"),
|
|
89
|
+
psdEphemeralKey: zPubKey.describe("TODO describe"),
|
|
90
|
+
psdEphemeralKeyAttestation: zHsmCertificate.describe("TODO describe")
|
|
91
|
+
}).describe("TODO describe");
|
|
92
|
+
var zUserRegistrationChallenge = z.object({
|
|
93
|
+
challenge: z.string().describe("TODO describe"),
|
|
94
|
+
ephemeralPublicKey: zPubKey.describe("TODO describe"),
|
|
95
|
+
ephemeralPublicKeyAttestation: zHsmCertificate.describe("TODO describe"),
|
|
96
|
+
handshake: zHexString.describe("TODO describe"),
|
|
97
|
+
handshakeAttestation: zHsmCertificate.describe("TODO describe"),
|
|
98
|
+
u2fRegisterData: z.string().describe("TODO describe"),
|
|
99
|
+
ciphertext: z.string().describe("TODO describe"),
|
|
100
|
+
requestId: z.string().describe("TODO describe")
|
|
101
|
+
}).describe("TODO describe");
|
|
102
|
+
z.object({
|
|
103
|
+
certificate: zHsmCertificate.describe("TODO describe"),
|
|
104
|
+
u2fRegister: zHexString.describe("TODO describe"),
|
|
105
|
+
u2fKeyHandle: zHexString.describe("TODO describe"),
|
|
106
|
+
registerData: z.string().describe("TODO describe"),
|
|
107
|
+
validationKey: zPubKey.describe("TODO describe"),
|
|
108
|
+
pairingPayload: z.string().describe("TODO describe")
|
|
109
|
+
}).describe("TODO describe");
|
|
110
|
+
z.object({
|
|
111
|
+
confidentialityKeyCurve25519: z.string(),
|
|
112
|
+
confidentialityKeySignature: z.string()
|
|
113
|
+
});
|
|
114
|
+
z.object({
|
|
115
|
+
pairing: z.object({
|
|
116
|
+
workspaceName: z.string(),
|
|
117
|
+
partitionKey: z.string(),
|
|
118
|
+
// TODO: Is this `zPubKey`?
|
|
119
|
+
bootstrapEnabled: z.boolean()
|
|
120
|
+
}),
|
|
121
|
+
// TODO: Is this `zHsmCertificate`?
|
|
122
|
+
partitionKeyAttestation: z.object({
|
|
123
|
+
codeHash: z.string(),
|
|
124
|
+
attestationPub: z.string(),
|
|
125
|
+
certificate: z.string(),
|
|
126
|
+
signature: z.string()
|
|
127
|
+
}),
|
|
128
|
+
blob: zBlob
|
|
129
|
+
});
|
|
130
|
+
var zBigInt = z.string().regex(/^0|[1-9]\d*$/);
|
|
131
|
+
var zIntString = z.string().min(1).regex(/^-?\d+$/);
|
|
132
|
+
var zBitcoinLikeTransactionType = z5.enum(["BITCOIN_LIKE_SEND", "BITCOIN_LIKE_RECEIVE"]).describe("Bitcoin-like transaction type");
|
|
133
|
+
var zCardanoLikeTransactionType = z5.enum([
|
|
134
|
+
"CARDANO_LIKE_SEND",
|
|
135
|
+
"CARDANO_LIKE_RECEIVE",
|
|
136
|
+
"CARDANO_LIKE_STAKING_REGISTER",
|
|
137
|
+
"CARDANO_LIKE_STAKING_DEREGISTER",
|
|
138
|
+
"CARDANO_LIKE_STAKING_DELEGATE",
|
|
139
|
+
"CARDANO_LIKE_STAKING_WITHDRAW"
|
|
140
|
+
]).describe("Cardano-like transaction type");
|
|
141
|
+
var zEthereumLikeTransferTransactionType = z5.enum(["ETHEREUM_LIKE_SEND", "ETHEREUM_LIKE_RECEIVE"]).describe("Ethereum-like transaction type");
|
|
142
|
+
var zEthereumLikeContractTransactionType = z5.enum(["ETHEREUM_LIKE_EXECUTE_CONTRACT", "ETHEREUM_LIKE_DEPLOY_CONTRACT"]).describe("Ethereum-like transaction type");
|
|
143
|
+
var zPolkadotLikeTransactionType = z5.enum([
|
|
144
|
+
"POLKADOT_LIKE_SEND",
|
|
145
|
+
"POLKADOT_LIKE_RECEIVE",
|
|
146
|
+
"POLKADOT_LIKE_ADDPROXY",
|
|
147
|
+
"POLKADOT_LIKE_REMOVEPROXY",
|
|
148
|
+
"POLKADOT_LIKE_BOND",
|
|
149
|
+
"POLKADOT_LIKE_REBOND",
|
|
150
|
+
"POLKADOT_LIKE_BONDEXTRA",
|
|
151
|
+
"POLKADOT_LIKE_UNBOND",
|
|
152
|
+
"POLKADOT_LIKE_WITHDRAWUNBONDED",
|
|
153
|
+
"POLKADOT_LIKE_SETCONTROLLER",
|
|
154
|
+
"POLKADOT_LIKE_SETPAYEE",
|
|
155
|
+
"POLKADOT_LIKE_PROXY",
|
|
156
|
+
"POLKADOT_LIKE_ANONYMOUSPROXY",
|
|
157
|
+
"POLKADOT_LIKE_KILLANONYMOUS",
|
|
158
|
+
"POLKADOT_LIKE_PUREPROXY",
|
|
159
|
+
"POLKADOT_LIKE_KILLPURE",
|
|
160
|
+
"POLKADOT_LIKE_NOMINATE",
|
|
161
|
+
"POLKADOT_LIKE_REWARD",
|
|
162
|
+
"POLKADOT_LIKE_CHILL",
|
|
163
|
+
"POLKADOT_LIKE_TRANSFERALL"
|
|
164
|
+
]).describe("Polkadot-like transaction type");
|
|
165
|
+
var zRippleLikeTransactionType = z5.enum(["RIPPLE_LIKE_SEND", "RIPPLE_LIKE_RECEIVE"]).describe("Ripple-like transaction type");
|
|
166
|
+
var zSolanaLikeTransactionType = z5.enum([
|
|
167
|
+
"SOLANA_LIKE_SEND",
|
|
168
|
+
"SOLANA_LIKE_RECEIVE",
|
|
169
|
+
"SOLANA_LIKE_CREATE_DELEGATE_STAKE",
|
|
170
|
+
"SOLANA_LIKE_DELEGATE_STAKE",
|
|
171
|
+
"SOLANA_LIKE_WITHDRAW_STAKE",
|
|
172
|
+
"SOLANA_LIKE_DEACTIVATE_STAKE",
|
|
173
|
+
"SOLANA_LIKE_SPLIT_STAKE",
|
|
174
|
+
"SOLANA_LIKE_SPLIT_DEACTIVATE_STAKE",
|
|
175
|
+
"SOLANA_LIKE_MERGE_STAKE",
|
|
176
|
+
"SOLANA_LIKE_SEND_TOKEN",
|
|
177
|
+
"SOLANA_LIKE_FUND_TOKEN"
|
|
178
|
+
]).describe("Solana-like transaction type");
|
|
179
|
+
var zStellarLikeTransactionType = z5.enum(["STELLAR_LIKE_SEND", "STELLAR_LIKE_RECEIVE"]).describe("Stellar-like transaction type");
|
|
180
|
+
var zTezosLikeTransactionType = z5.enum([
|
|
181
|
+
"TEZOS_LIKE_SEND",
|
|
182
|
+
"TEZOS_LIKE_RECEIVE",
|
|
183
|
+
"TEZOS_LIKE_REVEAL",
|
|
184
|
+
"TEZOS_LIKE_DELEGATE",
|
|
185
|
+
"TEZOS_LIKE_UNDELEGATE"
|
|
186
|
+
]).describe("Tezos-like transaction type");
|
|
187
|
+
var zGenericTransactionType = z5.enum(["GENERIC_TRANSACTION"]).describe("Generic transaction type");
|
|
188
|
+
z5.union([
|
|
189
|
+
zBitcoinLikeTransactionType,
|
|
190
|
+
zCardanoLikeTransactionType,
|
|
191
|
+
zEthereumLikeTransferTransactionType,
|
|
192
|
+
zEthereumLikeContractTransactionType,
|
|
193
|
+
zGenericTransactionType,
|
|
194
|
+
zPolkadotLikeTransactionType,
|
|
195
|
+
zRippleLikeTransactionType,
|
|
196
|
+
zSolanaLikeTransactionType,
|
|
197
|
+
zStellarLikeTransactionType,
|
|
198
|
+
zTezosLikeTransactionType
|
|
199
|
+
]);
|
|
200
|
+
|
|
201
|
+
// src/transactions/request-data.ts
|
|
202
|
+
var zHexDataString = z5.string().regex(/^(?:0x|0X)?[a-fA-F0-9]+$/).transform((hex) => `0x${hex.toLowerCase().replace("0x", "")}`);
|
|
203
|
+
if ("openapi" in zHexDataString) {
|
|
204
|
+
zHexDataString = zHexDataString.openapi?.({ effectType: "same" });
|
|
205
|
+
}
|
|
206
|
+
var zCommonTransactionData = z5.object({
|
|
207
|
+
amount: zBigInt.describe("Transaction amount"),
|
|
208
|
+
currency: z5.string().describe("Transaction currency"),
|
|
209
|
+
// TODO: strict literal or enum?
|
|
210
|
+
maxFee: zBigInt.nullable().describe("Transaction max fee"),
|
|
211
|
+
recipient: z5.string().describe("Transaction recipient")
|
|
212
|
+
});
|
|
213
|
+
var zFeeStrategyCustom = z5.object({
|
|
214
|
+
type: z5.enum(["SLOW", "NORMAL", "FAST", "CUSTOM"])
|
|
215
|
+
});
|
|
216
|
+
var zFeeStrategy = z5.object({
|
|
217
|
+
type: z5.enum(["SLOW", "NORMAL", "FAST"])
|
|
218
|
+
});
|
|
219
|
+
var zBitcoinLikeFeeStrategy = zFeeStrategyCustom.extend({
|
|
220
|
+
// nullish is optional + nullable, it is easier to seed rather than just optional
|
|
221
|
+
feePerByte: zBigInt.nullish().describe("Fee per byte")
|
|
222
|
+
}).describe("Bitcoin-like fee strategy");
|
|
223
|
+
var zBitcoinLikeSendData = zCommonTransactionData.extend({
|
|
224
|
+
type: z5.literal(zBitcoinLikeTransactionType.enum.BITCOIN_LIKE_SEND),
|
|
225
|
+
feeStrategy: zBitcoinLikeFeeStrategy
|
|
226
|
+
}).describe("Bitcoin-like send data");
|
|
227
|
+
var zEthereumLikeLegacyFeeStrategy = zFeeStrategyCustom.extend({ gasPrice: zBigInt.describe("Gas price"), gasLimit: zBigInt.describe("Gas limit") }).describe("Ethereum-like legacy fee strategy");
|
|
228
|
+
var zEthereumLikeEip1559FeeStrategy = zFeeStrategyCustom.extend({
|
|
229
|
+
maxPriorityFeePerGas: zBigInt.describe("Maximum priority fee per gas"),
|
|
230
|
+
maxFeePerGas: zBigInt.describe("Maximum fee per gas (base + priority)"),
|
|
231
|
+
gasLimit: zBigInt.describe("Gas limit")
|
|
232
|
+
}).describe("Ethereum-like EIP-1559 fee strategy");
|
|
233
|
+
var zEthereumLikeFeeStrategy = z5.union([zEthereumLikeLegacyFeeStrategy, zEthereumLikeEip1559FeeStrategy]).describe("Ethereum-like fee strategy");
|
|
234
|
+
var zEthereumLikeDeployContractData = zCommonTransactionData.extend({
|
|
235
|
+
type: z5.literal(zEthereumLikeContractTransactionType.enum.ETHEREUM_LIKE_DEPLOY_CONTRACT),
|
|
236
|
+
// force the recipient to be the zero address
|
|
237
|
+
recipient: z5.literal("0x0000000000000000000000000000000000000000"),
|
|
238
|
+
contractData: zHexDataString.describe("Contract data in hexadecimal format"),
|
|
239
|
+
feeStrategy: zEthereumLikeFeeStrategy
|
|
240
|
+
}).describe("Ethereum-like deploy contract data");
|
|
241
|
+
var zEthereumLikeExecuteContractData = zCommonTransactionData.extend({
|
|
242
|
+
type: z5.literal(zEthereumLikeContractTransactionType.enum.ETHEREUM_LIKE_EXECUTE_CONTRACT),
|
|
243
|
+
contractData: zHexDataString.describe("Contract call data in hexadecimal format"),
|
|
244
|
+
feeStrategy: zEthereumLikeFeeStrategy
|
|
245
|
+
}).describe("Ethereum-like execute contract data");
|
|
246
|
+
var zEthereumLikeSendData = zCommonTransactionData.extend({
|
|
247
|
+
type: z5.literal(zEthereumLikeTransferTransactionType.enum.ETHEREUM_LIKE_SEND),
|
|
248
|
+
feeStrategy: zEthereumLikeFeeStrategy
|
|
249
|
+
}).describe("Ethereum-like send data");
|
|
250
|
+
var zTezosLikeFeeStrategy = zFeeStrategyCustom.extend({
|
|
251
|
+
gasLimit: zBigInt.describe("Gas limit"),
|
|
252
|
+
storageLimit: zBigInt.nullable().describe("Storage limit")
|
|
253
|
+
}).describe("Tezos-like fee strategy");
|
|
254
|
+
var zTezosLikeDelegateData = zCommonTransactionData.extend({
|
|
255
|
+
type: z5.literal(zTezosLikeTransactionType.enum.TEZOS_LIKE_DELEGATE),
|
|
256
|
+
feeStrategy: zTezosLikeFeeStrategy
|
|
257
|
+
}).describe("Tezos-like delegate data");
|
|
258
|
+
var zTezosLikeSendData = zCommonTransactionData.extend({
|
|
259
|
+
type: z5.literal(zTezosLikeTransactionType.enum.TEZOS_LIKE_SEND),
|
|
260
|
+
feeStrategy: zTezosLikeFeeStrategy
|
|
261
|
+
}).describe("Tezos-like send data");
|
|
262
|
+
var zTezosLikeUndelegateData = zCommonTransactionData.extend({
|
|
263
|
+
type: z5.literal(zTezosLikeTransactionType.enum.TEZOS_LIKE_UNDELEGATE),
|
|
264
|
+
feeStrategy: zTezosLikeFeeStrategy
|
|
265
|
+
}).describe("Tezos-like undelegate data");
|
|
266
|
+
var zPolkadotRewardDestination = z5.enum(["Staked", "Stash"]);
|
|
267
|
+
var zPolkadotLikeAddProxyData = z5.object({
|
|
268
|
+
type: z5.literal(zPolkadotLikeTransactionType.enum.POLKADOT_LIKE_ADDPROXY),
|
|
269
|
+
currency: z5.string().describe("Transaction currency"),
|
|
270
|
+
kind: z5.literal("Staking").describe("Proxy kind"),
|
|
271
|
+
proxy: z5.string().describe("Proxy address")
|
|
272
|
+
}).describe("Polkadot-like add proxy data");
|
|
273
|
+
var zPolkadotLikeAnonymousProxyData = z5.object({
|
|
274
|
+
type: z5.literal(zPolkadotLikeTransactionType.enum.POLKADOT_LIKE_ANONYMOUSPROXY),
|
|
275
|
+
currency: z5.string().describe("Transaction currency")
|
|
276
|
+
}).describe("Polkadot-like anonymous proxy data");
|
|
277
|
+
var zPolkadotLikeBondData = z5.object({
|
|
278
|
+
type: z5.literal(zPolkadotLikeTransactionType.enum.POLKADOT_LIKE_BOND),
|
|
279
|
+
currency: z5.string().describe("Transaction currency"),
|
|
280
|
+
payee: zPolkadotRewardDestination,
|
|
281
|
+
amount: zBigInt.describe("Amount")
|
|
282
|
+
}).describe("Polkadot-like bond data");
|
|
283
|
+
var zPolkadotLikeBondExtraData = z5.object({
|
|
284
|
+
type: z5.literal(zPolkadotLikeTransactionType.enum.POLKADOT_LIKE_BONDEXTRA),
|
|
285
|
+
currency: z5.string().describe("Transaction currency"),
|
|
286
|
+
amount: zBigInt.describe("Amount")
|
|
287
|
+
}).describe("Polkadot-like bond extra data");
|
|
288
|
+
var zPolkadotLikeChillData = z5.object({
|
|
289
|
+
type: z5.literal(zPolkadotLikeTransactionType.enum.POLKADOT_LIKE_CHILL),
|
|
290
|
+
currency: z5.string().describe("Transaction currency")
|
|
291
|
+
}).describe("Polkadot-like chill data");
|
|
292
|
+
var zPolkadotLikeKillAnonymousData = z5.object({
|
|
293
|
+
type: z5.literal(zPolkadotLikeTransactionType.enum.POLKADOT_LIKE_KILLANONYMOUS),
|
|
294
|
+
currency: z5.string().describe("Transaction currency")
|
|
295
|
+
}).describe("Polkadot-like kill anonymous data");
|
|
296
|
+
var zPolkadotLikeRebondData = z5.object({
|
|
297
|
+
type: z5.literal(zPolkadotLikeTransactionType.enum.POLKADOT_LIKE_REBOND),
|
|
298
|
+
currency: z5.string().describe("Transaction currency"),
|
|
299
|
+
amount: zBigInt.describe("Amount")
|
|
300
|
+
}).describe("Polkadot-like rebond data");
|
|
301
|
+
var zPolkadotLikeRemoveProxyData = z5.object({
|
|
302
|
+
type: z5.literal(zPolkadotLikeTransactionType.enum.POLKADOT_LIKE_REMOVEPROXY),
|
|
303
|
+
currency: z5.string().describe("Transaction currency"),
|
|
304
|
+
kind: z5.literal("Staking"),
|
|
305
|
+
proxy: z5.string().describe("Proxy address")
|
|
306
|
+
}).describe("Polkadot-like remove proxy data");
|
|
307
|
+
var zPolkadotLikeSendData = zCommonTransactionData.extend({
|
|
308
|
+
type: z5.literal(zPolkadotLikeTransactionType.enum.POLKADOT_LIKE_SEND)
|
|
309
|
+
}).describe("Polkadot-like send data");
|
|
310
|
+
var zPolkadotLikeSetPayeeData = z5.object({
|
|
311
|
+
type: z5.literal(zPolkadotLikeTransactionType.enum.POLKADOT_LIKE_SETPAYEE),
|
|
312
|
+
currency: z5.string().describe("Transaction currency"),
|
|
313
|
+
payee: zPolkadotRewardDestination
|
|
314
|
+
}).describe("Polkadot-like set payee data");
|
|
315
|
+
var zPolkadotLikeUnbondData = z5.object({
|
|
316
|
+
type: z5.literal(zPolkadotLikeTransactionType.enum.POLKADOT_LIKE_UNBOND),
|
|
317
|
+
currency: z5.string().describe("Transaction currency"),
|
|
318
|
+
amount: zBigInt.describe("Amount")
|
|
319
|
+
}).describe("Polkadot-like unbond data");
|
|
320
|
+
var zPolkadotLikeWithdrawUnbondedData = z5.object({
|
|
321
|
+
type: z5.literal(zPolkadotLikeTransactionType.enum.POLKADOT_LIKE_WITHDRAWUNBONDED),
|
|
322
|
+
currency: z5.string().describe("Transaction currency")
|
|
323
|
+
}).describe("Polkadot-like withdraw unbonded data");
|
|
324
|
+
var zRippleLikeSendData = zCommonTransactionData.extend({
|
|
325
|
+
type: z5.literal(zRippleLikeTransactionType.enum.RIPPLE_LIKE_SEND),
|
|
326
|
+
destinationTag: zIntString.nullable().describe("Destination tag"),
|
|
327
|
+
feeStrategy: zFeeStrategyCustom.describe("Ripple-like fee strategy")
|
|
328
|
+
}).describe("Ripple-like send data");
|
|
329
|
+
var zStellarMemo = z5.union([
|
|
330
|
+
z5.object({ MEMO_TEXT: z5.string().max(28).describe("Text memo (at most a 28 bytes string)") }).describe("Text memo"),
|
|
331
|
+
z5.object({ MEMO_ID: zIntString.describe("Id memo (unsigned 64 bits integer)") }).describe("Id memo"),
|
|
332
|
+
z5.object({
|
|
333
|
+
MEMO_HASH: z5.string().max(128).regex(/^[a-fA-F0-9]+$/).describe("Transaction hash memo (64 bytes hexadecimal string)")
|
|
334
|
+
}).describe("Hash memo"),
|
|
335
|
+
z5.object({
|
|
336
|
+
MEMO_RETURN: z5.string().max(128).regex(/^[a-fA-F0-9]+$/).describe(
|
|
337
|
+
"A 64 bytes hexadecimal string intended to be interpreted as the hash of the transaction the sender is refunding."
|
|
338
|
+
)
|
|
339
|
+
}).describe("Return memo")
|
|
340
|
+
]);
|
|
341
|
+
var zStellarLikeSendData = zCommonTransactionData.extend({
|
|
342
|
+
type: z5.literal(zStellarLikeTransactionType.enum.STELLAR_LIKE_SEND),
|
|
343
|
+
memo: zStellarMemo.nullable().describe("Stellar memo"),
|
|
344
|
+
feeStrategy: zFeeStrategy.describe("Stellar-like fee strategy")
|
|
345
|
+
}).describe("Stellar-like send data");
|
|
346
|
+
var zSolanaLikeCreateDelegateStakeData = zCommonTransactionData.extend({
|
|
347
|
+
type: z5.literal(zSolanaLikeTransactionType.enum.SOLANA_LIKE_CREATE_DELEGATE_STAKE),
|
|
348
|
+
recipient: z5.string().describe("Delegated vote address"),
|
|
349
|
+
// Re-described
|
|
350
|
+
feeStrategy: zFeeStrategy.describe("Solana-like fee strategy")
|
|
351
|
+
}).describe("Solana-like create delegate stake data");
|
|
352
|
+
var zSolanaLikeDeactivateStakeData = z5.object({
|
|
353
|
+
type: z5.literal(zSolanaLikeTransactionType.enum.SOLANA_LIKE_DEACTIVATE_STAKE),
|
|
354
|
+
currency: z5.string().describe("Transaction currency"),
|
|
355
|
+
maxFee: zBigInt.nullable().describe("Transaction max fee"),
|
|
356
|
+
stakeAccount: z5.string().describe("Stake account address"),
|
|
357
|
+
feeStrategy: zFeeStrategy.describe("Solana-like fee strategy")
|
|
358
|
+
// No recipient, no amount
|
|
359
|
+
}).describe("Solana-like deactivate stake data");
|
|
360
|
+
var zSolanaLikeDelegateStakeData = z5.object({
|
|
361
|
+
type: z5.literal(zSolanaLikeTransactionType.enum.SOLANA_LIKE_DELEGATE_STAKE),
|
|
362
|
+
currency: z5.string().describe("Transaction currency"),
|
|
363
|
+
maxFee: zBigInt.nullable().describe("Transaction max fee"),
|
|
364
|
+
recipient: z5.string().describe("Delegated vote address"),
|
|
365
|
+
stakeAccount: z5.string().describe("Stake account address"),
|
|
366
|
+
feeStrategy: zFeeStrategy.describe("Solana-like fee strategy")
|
|
367
|
+
// No amount
|
|
368
|
+
}).describe("Solana-like delegate stake data");
|
|
369
|
+
var zSolanaLikeMergeStakeData = z5.object({
|
|
370
|
+
type: z5.literal(zSolanaLikeTransactionType.enum.SOLANA_LIKE_MERGE_STAKE),
|
|
371
|
+
currency: z5.string().describe("Transaction currency"),
|
|
372
|
+
maxFee: zBigInt.nullable().describe("Transaction max fee"),
|
|
373
|
+
mergeSrcAccount: z5.string().describe("Source stake address"),
|
|
374
|
+
mergeDstAccount: z5.string().describe("Destination stake address"),
|
|
375
|
+
feeStrategy: zFeeStrategy.describe("Solana-like fee strategy")
|
|
376
|
+
// No recipient, no amount
|
|
377
|
+
}).describe("Solana-like merge stake data");
|
|
378
|
+
var zSolanaLikeSendData = zCommonTransactionData.extend({
|
|
379
|
+
type: z5.literal(zSolanaLikeTransactionType.enum.SOLANA_LIKE_SEND),
|
|
380
|
+
feeStrategy: zFeeStrategy.describe("Solana-like fee strategy")
|
|
381
|
+
}).describe("Solana-like send data");
|
|
382
|
+
var zSolanaLikeSplitDeactivateStakeData = z5.object({
|
|
383
|
+
type: z5.literal(zSolanaLikeTransactionType.enum.SOLANA_LIKE_SPLIT_DEACTIVATE_STAKE),
|
|
384
|
+
amount: zBigInt.describe("Transaction amount"),
|
|
385
|
+
currency: z5.string().describe("Transaction currency"),
|
|
386
|
+
maxFee: zBigInt.nullable().describe("Transaction max fee"),
|
|
387
|
+
stakeAccount: z5.string().describe("Stake account address"),
|
|
388
|
+
feeStrategy: zFeeStrategy.describe("Solana-like fee strategy")
|
|
389
|
+
// No recipient
|
|
390
|
+
}).describe("Solana-like split deactivate stake data");
|
|
391
|
+
var zSolanaLikeSplitStakeData = z5.object({
|
|
392
|
+
type: z5.literal(zSolanaLikeTransactionType.enum.SOLANA_LIKE_SPLIT_STAKE),
|
|
393
|
+
amount: zBigInt.describe("Transaction amount"),
|
|
394
|
+
currency: z5.string().describe("Transaction currency"),
|
|
395
|
+
maxFee: zBigInt.nullable().describe("Transaction max fee"),
|
|
396
|
+
stakeAccount: z5.string().describe("Stake account address"),
|
|
397
|
+
feeStrategy: zFeeStrategy.describe("Solana-like fee strategy")
|
|
398
|
+
// No recipient
|
|
399
|
+
}).describe("Solana-like split stake data");
|
|
400
|
+
var zSolanaLikeWithdrawStakeData = z5.object({
|
|
401
|
+
type: z5.literal(zSolanaLikeTransactionType.enum.SOLANA_LIKE_WITHDRAW_STAKE),
|
|
402
|
+
amount: zBigInt.describe("Transaction amount"),
|
|
403
|
+
currency: z5.string().describe("Transaction currency"),
|
|
404
|
+
maxFee: zBigInt.nullable().describe("Transaction max fee"),
|
|
405
|
+
stakeAccount: z5.string().describe("Stake account address"),
|
|
406
|
+
feeStrategy: zFeeStrategy.describe("Solana-like fee strategy")
|
|
407
|
+
// No recipient
|
|
408
|
+
}).describe("Solana-like delegate stake data");
|
|
409
|
+
var zSolanaLikeSendTokenData = zCommonTransactionData.extend({
|
|
410
|
+
type: z5.literal(zSolanaLikeTransactionType.enum.SOLANA_LIKE_SEND_TOKEN),
|
|
411
|
+
feeStrategy: zFeeStrategy.describe("Solana-like fee strategy")
|
|
412
|
+
}).describe("Solana-like send token data");
|
|
413
|
+
var zSolanaLikeFundTokenData = zCommonTransactionData.extend({
|
|
414
|
+
type: z5.literal(zSolanaLikeTransactionType.enum.SOLANA_LIKE_FUND_TOKEN),
|
|
415
|
+
feeStrategy: zFeeStrategy.describe("Solana-like fee strategy")
|
|
416
|
+
}).describe("Solana-like fund token data");
|
|
417
|
+
var zCardanoSendData = zCommonTransactionData.extend({
|
|
418
|
+
type: z5.literal(zCardanoLikeTransactionType.enum.CARDANO_LIKE_SEND),
|
|
419
|
+
feeStrategy: zFeeStrategy.describe("Cardano-like fee strategy")
|
|
420
|
+
}).describe("Cardano-like send data");
|
|
421
|
+
var zCardanoStakingDelegateData = z5.object({
|
|
422
|
+
type: z5.literal(zCardanoLikeTransactionType.enum.CARDANO_LIKE_STAKING_DELEGATE),
|
|
423
|
+
currency: z5.string().describe("Transaction currency"),
|
|
424
|
+
// TODO: strict literal or enum?
|
|
425
|
+
maxFee: zBigInt.nullable().describe("Transaction max fee"),
|
|
426
|
+
feeStrategy: zFeeStrategy.describe("Cardano-like fee strategy"),
|
|
427
|
+
// DELEGATE doesn't have neither amount nor recipient
|
|
428
|
+
stakePoolId: z5.string().min(1).max(100).describe("")
|
|
429
|
+
}).describe("Cardano-like staking delegate");
|
|
430
|
+
var zCardanoStakingDeregisterData = z5.object({
|
|
431
|
+
type: z5.literal(zCardanoLikeTransactionType.enum.CARDANO_LIKE_STAKING_DEREGISTER),
|
|
432
|
+
currency: z5.string().describe("Transaction currency"),
|
|
433
|
+
// TODO: strict literal or enum?
|
|
434
|
+
maxFee: zBigInt.nullable().describe("Transaction max fee"),
|
|
435
|
+
feeStrategy: zFeeStrategy.describe("Cardano-like fee strategy"),
|
|
436
|
+
// DEREGISTER doesn't have a recipient
|
|
437
|
+
amount: zBigInt.describe("Amount to deregister")
|
|
438
|
+
}).describe("Cardano-like staking deregister data");
|
|
439
|
+
var zCardanoStakingRegisterData = z5.object({
|
|
440
|
+
type: z5.literal(zCardanoLikeTransactionType.enum.CARDANO_LIKE_STAKING_REGISTER),
|
|
441
|
+
currency: z5.string().describe("Transaction currency"),
|
|
442
|
+
// TODO: strict literal or enum?
|
|
443
|
+
maxFee: zBigInt.nullable().describe("Transaction max fee"),
|
|
444
|
+
feeStrategy: zFeeStrategy.describe("Cardano-like fee strategy"),
|
|
445
|
+
// REGISTER doesn't have a recipient
|
|
446
|
+
amount: zBigInt.describe("Amount to register")
|
|
447
|
+
}).describe("Cardano-like staking register data");
|
|
448
|
+
var zCardanoStakingWithdrawData = z5.object({
|
|
449
|
+
type: z5.literal(zCardanoLikeTransactionType.enum.CARDANO_LIKE_STAKING_WITHDRAW),
|
|
450
|
+
currency: z5.string().describe("Transaction currency"),
|
|
451
|
+
// TODO: strict literal or enum?
|
|
452
|
+
maxFee: zBigInt.nullable().describe("Transaction max fee"),
|
|
453
|
+
feeStrategy: zFeeStrategy.describe("Cardano-like fee strategy"),
|
|
454
|
+
// WITHDRAW doesn't have a recipient
|
|
455
|
+
amount: zBigInt.describe("Amount to withdraw")
|
|
456
|
+
}).describe("Cardano-like staking withdraw data");
|
|
457
|
+
var zGenericTransactionData = z5.object({
|
|
458
|
+
type: z5.literal(zGenericTransactionType.enum.GENERIC_TRANSACTION),
|
|
459
|
+
currency: z5.string().describe("Transaction currency"),
|
|
460
|
+
rawTx: z5.string().describe("Raw tx")
|
|
461
|
+
}).describe("Generic transaction data");
|
|
462
|
+
var zTransactionData = z5.discriminatedUnion("type", [
|
|
463
|
+
// Bitcoin
|
|
464
|
+
zBitcoinLikeSendData,
|
|
465
|
+
// Cardano
|
|
466
|
+
zCardanoSendData,
|
|
467
|
+
zCardanoStakingDelegateData,
|
|
468
|
+
zCardanoStakingDeregisterData,
|
|
469
|
+
zCardanoStakingRegisterData,
|
|
470
|
+
zCardanoStakingWithdrawData,
|
|
471
|
+
// Ethereum
|
|
472
|
+
zEthereumLikeDeployContractData,
|
|
473
|
+
zEthereumLikeExecuteContractData,
|
|
474
|
+
zEthereumLikeSendData,
|
|
475
|
+
// Generic
|
|
476
|
+
zGenericTransactionData,
|
|
477
|
+
// Polkadot
|
|
478
|
+
zPolkadotLikeAddProxyData,
|
|
479
|
+
zPolkadotLikeAnonymousProxyData,
|
|
480
|
+
zPolkadotLikeBondData,
|
|
481
|
+
zPolkadotLikeBondExtraData,
|
|
482
|
+
zPolkadotLikeChillData,
|
|
483
|
+
zPolkadotLikeKillAnonymousData,
|
|
484
|
+
zPolkadotLikeRebondData,
|
|
485
|
+
zPolkadotLikeRemoveProxyData,
|
|
486
|
+
zPolkadotLikeSendData,
|
|
487
|
+
zPolkadotLikeSetPayeeData,
|
|
488
|
+
zPolkadotLikeUnbondData,
|
|
489
|
+
zPolkadotLikeWithdrawUnbondedData,
|
|
490
|
+
// Ripple
|
|
491
|
+
zRippleLikeSendData,
|
|
492
|
+
// Solana
|
|
493
|
+
zSolanaLikeCreateDelegateStakeData,
|
|
494
|
+
zSolanaLikeDeactivateStakeData,
|
|
495
|
+
zSolanaLikeDelegateStakeData,
|
|
496
|
+
zSolanaLikeMergeStakeData,
|
|
497
|
+
zSolanaLikeSendData,
|
|
498
|
+
zSolanaLikeSplitDeactivateStakeData,
|
|
499
|
+
zSolanaLikeSplitStakeData,
|
|
500
|
+
zSolanaLikeWithdrawStakeData,
|
|
501
|
+
zSolanaLikeSendTokenData,
|
|
502
|
+
zSolanaLikeFundTokenData,
|
|
503
|
+
// Stellar
|
|
504
|
+
zStellarLikeSendData,
|
|
505
|
+
// Tezos
|
|
506
|
+
zTezosLikeDelegateData,
|
|
507
|
+
zTezosLikeSendData,
|
|
508
|
+
zTezosLikeUndelegateData
|
|
509
|
+
]);
|
|
510
|
+
var zSendOnlyTransactionData = z5.discriminatedUnion("type", [
|
|
511
|
+
zBitcoinLikeSendData,
|
|
512
|
+
zCardanoSendData,
|
|
513
|
+
zEthereumLikeSendData,
|
|
514
|
+
zPolkadotLikeSendData,
|
|
515
|
+
zRippleLikeSendData,
|
|
516
|
+
zSolanaLikeSendData,
|
|
517
|
+
zStellarLikeSendData,
|
|
518
|
+
zTezosLikeSendData
|
|
519
|
+
]);
|
|
520
|
+
var zCreateTransactionRequestData = z5.object({
|
|
521
|
+
accountId: z5.string().min(1).describe("Target account id"),
|
|
522
|
+
transaction: zTransactionData
|
|
523
|
+
});
|
|
524
|
+
var zAccountOperationType = z.enum([
|
|
525
|
+
"SEND",
|
|
526
|
+
"STAKE",
|
|
527
|
+
"DEPLOY_CONTRACT",
|
|
528
|
+
"EXECUTE_CONTRACT",
|
|
529
|
+
"SIGN_DIGESTS",
|
|
530
|
+
"SIGN_MESSAGE",
|
|
531
|
+
"ACTIVATE_TOKEN"
|
|
532
|
+
]);
|
|
533
|
+
var zOperationType = z.enum([...zAccountOperationType.options]);
|
|
534
|
+
var zNote = z5.object({
|
|
535
|
+
title: z5.string().describe("Request note title"),
|
|
536
|
+
content: z5.string().describe("Request note content")
|
|
537
|
+
});
|
|
538
|
+
|
|
539
|
+
// src/accounts/clients/types.ts
|
|
540
|
+
var zTransactionStatus = z5.enum(["SUCCESSFUL", "FAILED"]);
|
|
541
|
+
var zBitcoinLikeCoinFields = z5.object({
|
|
542
|
+
type: zBitcoinLikeTransactionType
|
|
543
|
+
});
|
|
544
|
+
var zCardanoLikeCoinFields = z5.object({
|
|
545
|
+
type: zCardanoLikeTransactionType
|
|
546
|
+
});
|
|
547
|
+
var zEthereumLikeTransferCoinFields = z5.object({
|
|
548
|
+
type: zEthereumLikeTransferTransactionType,
|
|
549
|
+
gasPrice: z5.string(),
|
|
550
|
+
gasLimit: z5.string(),
|
|
551
|
+
nonce: z5.string()
|
|
552
|
+
});
|
|
553
|
+
var zEthereumLikeContractCoinFields = zEthereumLikeTransferCoinFields.extend({
|
|
554
|
+
type: zEthereumLikeContractTransactionType,
|
|
555
|
+
contractData: z5.string().describe("Contract deployment or contract execution data")
|
|
556
|
+
});
|
|
557
|
+
var zGenericCoinFields = z5.object({
|
|
558
|
+
type: zGenericTransactionType
|
|
559
|
+
});
|
|
560
|
+
var zPolkadotLikeCoinFields = z5.object({
|
|
561
|
+
type: zPolkadotLikeTransactionType
|
|
562
|
+
});
|
|
563
|
+
var zRippleLikeCoinFields = z5.object({
|
|
564
|
+
type: zRippleLikeTransactionType,
|
|
565
|
+
memos: z5.array(z5.string()),
|
|
566
|
+
destinationTag: z5.string()
|
|
567
|
+
});
|
|
568
|
+
var zSolanaLikeCoinFields = z5.object({
|
|
569
|
+
type: zSolanaLikeTransactionType
|
|
570
|
+
});
|
|
571
|
+
var zStellarLikeCoinFields = z5.object({
|
|
572
|
+
type: zStellarLikeTransactionType
|
|
573
|
+
});
|
|
574
|
+
var zTezosLikeCoinFields = z5.object({
|
|
575
|
+
type: zTezosLikeTransactionType
|
|
576
|
+
});
|
|
577
|
+
var zCommonTransactionResponse = z5.object({
|
|
578
|
+
id: z5.string().describe("Internal unique identifier"),
|
|
579
|
+
hash: z5.string().describe("Transaction hash"),
|
|
580
|
+
block: z5.object({
|
|
581
|
+
height: z5.string().nullable().describe("Transaction block height"),
|
|
582
|
+
time: z5.string().nullable().describe("Transaction block time")
|
|
583
|
+
}),
|
|
584
|
+
status: zTransactionStatus.describe("Transaction status"),
|
|
585
|
+
confirmations: z5.string().describe("Block confirmations"),
|
|
586
|
+
amount: z5.string().describe("Transaction amount"),
|
|
587
|
+
fee: z5.string().describe("Transaction fee"),
|
|
588
|
+
senders: z5.array(z5.string()).describe("Senders (can be multiple for UTXOs-based accounts)"),
|
|
589
|
+
recipients: z5.array(z5.string()).describe("Recipients (can be multiple for multi-output transactions)")
|
|
590
|
+
});
|
|
591
|
+
var zBitcoinLikeTransactionResponse = zCommonTransactionResponse.merge(zBitcoinLikeCoinFields).describe("Bitcoin-like transaction");
|
|
592
|
+
var zCardanoLikeTransactionResponse = zCommonTransactionResponse.merge(zCardanoLikeCoinFields).describe("Cardano-like transaction");
|
|
593
|
+
var zEthereumLikeTransferTransactionResponse = zCommonTransactionResponse.merge(zEthereumLikeTransferCoinFields).describe("Ethereum-like transfer transaction");
|
|
594
|
+
var zEthereumLikeContractTransactionResponse = zCommonTransactionResponse.merge(zEthereumLikeContractCoinFields).describe("Ethereum-like contract transaction");
|
|
595
|
+
var zGenericTransactionResponse = zCommonTransactionResponse.merge(zGenericCoinFields).describe("Generic transaction");
|
|
596
|
+
var zPolkadotLikeTransactionResponse = zCommonTransactionResponse.merge(zPolkadotLikeCoinFields).describe("Polkadot-like transaction");
|
|
597
|
+
var zRippleLikeTransactionResponse = zCommonTransactionResponse.merge(zRippleLikeCoinFields).describe("Ripple-like transaction");
|
|
598
|
+
var zSolanaLikeTransactionResponse = zCommonTransactionResponse.merge(zSolanaLikeCoinFields).describe("Solana-like transaction");
|
|
599
|
+
var zStellarLikeTransactionResponse = zCommonTransactionResponse.merge(zStellarLikeCoinFields).describe("Stellar-like transaction");
|
|
600
|
+
var zTezosLikeTransactionResponse = zCommonTransactionResponse.merge(zTezosLikeCoinFields).describe("Tezos-like transaction");
|
|
601
|
+
var zTransactionResponse = z5.discriminatedUnion("type", [
|
|
602
|
+
zBitcoinLikeTransactionResponse,
|
|
603
|
+
zCardanoLikeTransactionResponse,
|
|
604
|
+
zEthereumLikeTransferTransactionResponse,
|
|
605
|
+
zEthereumLikeContractTransactionResponse,
|
|
606
|
+
zGenericTransactionResponse,
|
|
607
|
+
zPolkadotLikeTransactionResponse,
|
|
608
|
+
zRippleLikeTransactionResponse,
|
|
609
|
+
zSolanaLikeTransactionResponse,
|
|
610
|
+
zStellarLikeTransactionResponse,
|
|
611
|
+
zTezosLikeTransactionResponse
|
|
612
|
+
]);
|
|
613
|
+
z5.discriminatedUnion(
|
|
614
|
+
zTransactionResponse.discriminator,
|
|
615
|
+
ensureNonEmptyArray(
|
|
616
|
+
zTransactionResponse.options.map((_) => _.extend({ note: zNote.nullable() }))
|
|
617
|
+
)
|
|
618
|
+
);
|
|
619
|
+
var zCardanoLikeStakingData = z5.object({
|
|
620
|
+
staked: z5.string().describe("Staked balance")
|
|
621
|
+
}).nullable().describe("Cardano-like staking data");
|
|
622
|
+
var zCardanoLikeStakingFields = z5.object({
|
|
623
|
+
type: z5.literal(AccountType.CARDANO_LIKE).describe("Account type"),
|
|
624
|
+
staking: zCardanoLikeStakingData.optional()
|
|
625
|
+
});
|
|
626
|
+
var zEthereumLikeStakingData = z5.object({
|
|
627
|
+
totalStaking: z5.string().describe("Total staked amount"),
|
|
628
|
+
totalRewards: z5.string().describe("Total of rewards"),
|
|
629
|
+
availableRewards: z5.string().describe("Available rewards"),
|
|
630
|
+
networkApy: z5.number().describe("Network APY")
|
|
631
|
+
}).nullable().describe("Ethereum-like staking data");
|
|
632
|
+
var zEthereumLikeStakingFields = z5.object({
|
|
633
|
+
type: z5.literal(AccountType.ETHEREUM_LIKE).describe("Account type"),
|
|
634
|
+
staking: zEthereumLikeStakingData.optional()
|
|
635
|
+
});
|
|
636
|
+
var zPolkadotUnbondingAmount = z5.object({
|
|
637
|
+
amount: z5.string().describe("Amount"),
|
|
638
|
+
waiting_time: z5.string().describe("Waiting time")
|
|
639
|
+
});
|
|
640
|
+
var zPolkadotLikeStakingData = z5.object({
|
|
641
|
+
info: z5.object({
|
|
642
|
+
controllerAddress: z5.string().nullable().describe("Controller address"),
|
|
643
|
+
rewardsDestination: z5.string().nullable().describe("Rewards destination"),
|
|
644
|
+
proxies: z5.array(z5.string()).describe("Proxies"),
|
|
645
|
+
legacyStaking: z5.boolean().describe("True if account uses legacy staking"),
|
|
646
|
+
isNominator: z5.boolean().describe("True if is nominator")
|
|
647
|
+
}),
|
|
648
|
+
balances: z5.object({
|
|
649
|
+
free: z5.string().describe("Free balance"),
|
|
650
|
+
reserved: z5.string().describe("Reserved balance"),
|
|
651
|
+
frozen: z5.string().describe("Frozen balance"),
|
|
652
|
+
bonded: z5.string().describe("Bonded balance"),
|
|
653
|
+
available: z5.string().describe("Available balance"),
|
|
654
|
+
unbonding: z5.array(zPolkadotUnbondingAmount).describe("Unbonding balances"),
|
|
655
|
+
unbonded: z5.array(zPolkadotUnbondingAmount).describe("Unbonded balances"),
|
|
656
|
+
totalUnbonding: z5.string().describe("Total unbonding"),
|
|
657
|
+
totalUnbonded: z5.string().describe("Total unbonded")
|
|
658
|
+
}),
|
|
659
|
+
anonymousProxy: z5.object({
|
|
660
|
+
address: z5.string().describe("Address"),
|
|
661
|
+
createdAt: z5.string().describe("Creation date"),
|
|
662
|
+
isController: z5.boolean().describe("True if is controller"),
|
|
663
|
+
isMain: z5.boolean().describe("True if is main"),
|
|
664
|
+
balances: z5.object({
|
|
665
|
+
free: z5.string().describe("Anonymous proxy free balance"),
|
|
666
|
+
reserved: z5.string().describe("Anonymous proxy reserved balance"),
|
|
667
|
+
frozen: z5.string().describe("Anonymous proxy frozen balance"),
|
|
668
|
+
bonded: z5.string().describe("Anonymous proxy bonded balance"),
|
|
669
|
+
available: z5.string().describe("Anonymous proxy available balance"),
|
|
670
|
+
total: z5.string().describe("Anonymous proxy total balance")
|
|
671
|
+
}).nullable(),
|
|
672
|
+
blockHeight: z5.string().describe("Anonymous proxy block height"),
|
|
673
|
+
extIndex: z5.string().describe("Ext index"),
|
|
674
|
+
index: z5.string().describe("Index"),
|
|
675
|
+
kind: z5.string().describe("Kind")
|
|
676
|
+
}).nullable().describe("Anonymous proxy")
|
|
677
|
+
}).nullable().describe("Polkadot-like staking data");
|
|
678
|
+
var zPolkadotLikeStakingFields = z5.object({
|
|
679
|
+
type: z5.literal(AccountType.POLKADOT_LIKE).describe("Account type"),
|
|
680
|
+
staking: zPolkadotLikeStakingData.optional()
|
|
681
|
+
});
|
|
682
|
+
var zSolanaStakingAccountStatus = z5.enum(["not_sync", "activating", "activated", "deactivating", "deactivated", "deleted"]).describe("Staking account status");
|
|
683
|
+
var zSolanaLikeStakingData = z5.object({
|
|
684
|
+
staked: z5.string().describe("Staked balance"),
|
|
685
|
+
rewards: z5.object({
|
|
686
|
+
total: z5.string().describe("Total rewards"),
|
|
687
|
+
last7: z5.string().describe("Rewards on last 7 days"),
|
|
688
|
+
last30: z5.string().describe("Rewards on last 30 days")
|
|
689
|
+
}),
|
|
690
|
+
stakes: z5.array(
|
|
691
|
+
z5.object({
|
|
692
|
+
uid: z5.string(),
|
|
693
|
+
baseAccountUid: z5.string(),
|
|
694
|
+
pubKey: z5.string().describe("Public key"),
|
|
695
|
+
validatorPubKey: z5.string().nullable().describe("Validator public key"),
|
|
696
|
+
initialAmount: z5.string().describe("Initial amount"),
|
|
697
|
+
activeAmount: z5.string().describe("Active amount"),
|
|
698
|
+
inactiveAmount: z5.string().describe("Inactive amount"),
|
|
699
|
+
totalBalance: z5.string().describe("Total balance"),
|
|
700
|
+
creationDate: z5.string().describe("Creation date"),
|
|
701
|
+
activationEpoch: z5.string().nullable().describe("Activation epoch"),
|
|
702
|
+
activationDate: z5.string().nullable().describe("Activation date"),
|
|
703
|
+
deactivationEpoch: z5.string().nullable().describe("Deactivation epoch"),
|
|
704
|
+
deactivationDate: z5.string().nullable().describe("Deactivation date"),
|
|
705
|
+
status: zSolanaStakingAccountStatus,
|
|
706
|
+
rentExemptReserve: z5.string().describe("Rent exempt reserve"),
|
|
707
|
+
withdrawableAmount: z5.string().describe("Withdrawable amount"),
|
|
708
|
+
totalRewards: z5.string().describe("Total rewards"),
|
|
709
|
+
creationTxHash: z5.string().nullable().describe("Creation transaction hash"),
|
|
710
|
+
actionsTxHashes: z5.array(z5.string()).describe("Actions transactions hashes")
|
|
711
|
+
})
|
|
712
|
+
)
|
|
713
|
+
}).nullable().describe("Solana-like staking data");
|
|
714
|
+
var zSolanaLikeStakingFields = z5.object({
|
|
715
|
+
type: z5.literal(AccountType.SOLANA_LIKE).describe("Account type"),
|
|
716
|
+
staking: zSolanaLikeStakingData.optional()
|
|
717
|
+
});
|
|
718
|
+
var zTezosLikeStakingData = z5.object({
|
|
719
|
+
delegations: z5.array(
|
|
720
|
+
z5.object({
|
|
721
|
+
address: z5.string()
|
|
722
|
+
})
|
|
723
|
+
)
|
|
724
|
+
}).nullable().describe("Tezos-like staking data");
|
|
725
|
+
var zTezosLikeStakingFields = z5.object({
|
|
726
|
+
type: z5.literal(AccountType.TEZOS_LIKE).describe("Account type"),
|
|
727
|
+
staking: zTezosLikeStakingData.optional()
|
|
728
|
+
});
|
|
729
|
+
z5.discriminatedUnion("type", [
|
|
730
|
+
zCardanoLikeStakingFields,
|
|
731
|
+
zEthereumLikeStakingFields,
|
|
732
|
+
zPolkadotLikeStakingFields,
|
|
733
|
+
zSolanaLikeStakingFields,
|
|
734
|
+
zTezosLikeStakingFields
|
|
735
|
+
]);
|
|
736
|
+
|
|
737
|
+
// src/accounts/account-asset-fields.ts
|
|
738
|
+
var zBitcoinLikeAssetFields = z.object({
|
|
739
|
+
type: z.literal(AccountType.BITCOIN_LIKE).describe("Account type"),
|
|
740
|
+
xpub: z.string().describe("xpub (extended public key)")
|
|
741
|
+
}).describe("Bitcoin-like");
|
|
742
|
+
var zCardanoLikeAssetFields = z.object({
|
|
743
|
+
type: z.literal(AccountType.CARDANO_LIKE).describe("Account type"),
|
|
744
|
+
address: z.string().describe("Account address").nullable()
|
|
745
|
+
}).describe("Cardano-like");
|
|
746
|
+
var zEthereumLikeAssetFields = z.object({
|
|
747
|
+
type: z.literal(AccountType.ETHEREUM_LIKE).describe("Account type"),
|
|
748
|
+
address: z.string().describe("Account address").nullable()
|
|
749
|
+
}).describe("Ethereum-like");
|
|
750
|
+
var zEthereumTokenLikeAssetFields = z.object({
|
|
751
|
+
type: z.enum([AccountType.ERC20_LIKE, AccountType.BEP20_LIKE, AccountType.TRC20_LIKE]).describe("Account type"),
|
|
752
|
+
address: z.string().describe("Account address").nullable(),
|
|
753
|
+
contractAddress: z.string().describe("Token contract address")
|
|
754
|
+
}).describe("Ethereum-like token");
|
|
755
|
+
var zGenericLikeAssetFields = z.object({ type: z.literal(AccountType.GENERIC_LIKE).describe("Account type") }).describe("Generic-like");
|
|
756
|
+
var zPolkadotLikeAssetFields = z.object({
|
|
757
|
+
type: z.literal(AccountType.POLKADOT_LIKE).describe("Account type"),
|
|
758
|
+
address: z.string().describe("Account address").nullable()
|
|
759
|
+
}).describe("Polkadot-like");
|
|
760
|
+
var zRippleLikeAssetFields = z.object({
|
|
761
|
+
type: z.literal(AccountType.RIPPLE_LIKE).describe("Account type"),
|
|
762
|
+
xpub: z.string().describe("xpub (extended public key)")
|
|
763
|
+
}).describe("Ripple-like");
|
|
764
|
+
var zSolanaLikeAssetFields = z.object({
|
|
765
|
+
type: z.literal(AccountType.SOLANA_LIKE).describe("Account type"),
|
|
766
|
+
address: z.string().describe("Account address").nullable(),
|
|
767
|
+
contractAddress: z.string().describe("Token contract address").nullable()
|
|
768
|
+
}).describe("Solana-like");
|
|
769
|
+
var zStellarLikeAssetFields = z.object({
|
|
770
|
+
type: z.literal(AccountType.STELLAR_LIKE).describe("Account type"),
|
|
771
|
+
address: z.string().describe("Account address").nullable()
|
|
772
|
+
}).describe("Stellar-like");
|
|
773
|
+
var zTezosLikeAssetFields = z.object({
|
|
774
|
+
type: z.literal(AccountType.TEZOS_LIKE).describe("Account type"),
|
|
775
|
+
address: z.string().describe("Account address").nullable()
|
|
776
|
+
}).describe("Tezos-like");
|
|
777
|
+
z.discriminatedUnion("type", [
|
|
778
|
+
zBitcoinLikeAssetFields,
|
|
779
|
+
zCardanoLikeAssetFields,
|
|
780
|
+
zEthereumLikeAssetFields,
|
|
781
|
+
zEthereumTokenLikeAssetFields,
|
|
782
|
+
zGenericLikeAssetFields,
|
|
783
|
+
zPolkadotLikeAssetFields,
|
|
784
|
+
zRippleLikeAssetFields,
|
|
785
|
+
zSolanaLikeAssetFields,
|
|
786
|
+
zStellarLikeAssetFields,
|
|
787
|
+
zTezosLikeAssetFields
|
|
788
|
+
]).describe("Account asset fields");
|
|
789
|
+
var zAccountAssetFields = z.discriminatedUnion("type", [
|
|
790
|
+
zBitcoinLikeAssetFields,
|
|
791
|
+
zCardanoLikeAssetFields.merge(zCardanoLikeStakingFields).describe("Cardano-like"),
|
|
792
|
+
zEthereumLikeAssetFields.merge(zEthereumLikeStakingFields).describe("Ethereum-like"),
|
|
793
|
+
zEthereumTokenLikeAssetFields,
|
|
794
|
+
zGenericLikeAssetFields,
|
|
795
|
+
zPolkadotLikeAssetFields.merge(zPolkadotLikeStakingFields).describe("Polkadot-like"),
|
|
796
|
+
zRippleLikeAssetFields,
|
|
797
|
+
zSolanaLikeAssetFields.merge(zSolanaLikeStakingFields).describe("Solana-like"),
|
|
798
|
+
zStellarLikeAssetFields,
|
|
799
|
+
zTezosLikeAssetFields.merge(zTezosLikeStakingFields).describe("Tezos-like")
|
|
800
|
+
]).describe("Asset fields");
|
|
801
|
+
var zReviewStepWithUsers = z.object({
|
|
802
|
+
quorum: z.number().min(0).describe("Number of required approvals for the step"),
|
|
803
|
+
userIds: z.array(z.string().min(1)).describe("User ids in the step")
|
|
804
|
+
// PKs to `User` model
|
|
805
|
+
}).describe("Review step with users");
|
|
806
|
+
var zReviewStepWithUsersArray = z.array(zReviewStepWithUsers);
|
|
807
|
+
var zReviewStepData = z.union([
|
|
808
|
+
zReviewStepWithUsers,
|
|
809
|
+
z.object({
|
|
810
|
+
quorum: z.number().min(0).describe("Number of required approvals for the step"),
|
|
811
|
+
groupId: z.string().min(1).describe("Group id in the step")
|
|
812
|
+
// PKs to `Group` model
|
|
813
|
+
}).describe("Review step with group")
|
|
814
|
+
]);
|
|
815
|
+
var zReviewStepsArray = z.array(zReviewStepData).min(1).describe("Review steps");
|
|
816
|
+
var zWorkspaceName = z5.string().min(1).max(20).regex(/^[a-z0-9]+$/);
|
|
817
|
+
|
|
818
|
+
// src/tradelink/types.ts
|
|
819
|
+
var zTradelinkWhitelistAddress = z5.object({
|
|
820
|
+
name: z5.string().min(1),
|
|
821
|
+
currency: z5.string().min(1),
|
|
822
|
+
address: z5.string().min(1)
|
|
823
|
+
});
|
|
824
|
+
z5.array(zTradelinkWhitelistAddress);
|
|
825
|
+
var zTradelinkId = z5.string().describe("Unique identifier in Tradelink service");
|
|
826
|
+
var zTradelinkOrgEntityResponse = z5.object({
|
|
827
|
+
tradelinkId: zTradelinkId,
|
|
828
|
+
name: z5.string().describe("Name"),
|
|
829
|
+
code: z5.string().describe("Code"),
|
|
830
|
+
logoUrl: z5.string().describe("Logo URL")
|
|
831
|
+
});
|
|
832
|
+
zTradelinkOrgEntityResponse.omit({
|
|
833
|
+
tradelinkId: true
|
|
834
|
+
});
|
|
835
|
+
z5.object({
|
|
836
|
+
tradelinkId: zTradelinkId
|
|
837
|
+
});
|
|
838
|
+
var zTradelinkExchangeConfig = z5.object({
|
|
839
|
+
exchangeId: z5.string().describe("Tradelink exchange id"),
|
|
840
|
+
repledgeAuthorized: z5.boolean().describe("Determines whether this exchange is authorized to repledge on this account"),
|
|
841
|
+
needsAssetManagerApprovalForSettlements: z5.boolean().describe(
|
|
842
|
+
'Determines whether asset manager will "pre-approve" the settlement requests on this account'
|
|
843
|
+
)
|
|
844
|
+
});
|
|
845
|
+
var zTradelinkExchangeConfigs = z5.array(zTradelinkExchangeConfig);
|
|
846
|
+
z5.object({
|
|
847
|
+
workspaceName: zWorkspaceName,
|
|
848
|
+
custodian: z5.object({ name: z5.string() }),
|
|
849
|
+
assetManagers: z5.array(z5.object({ name: z5.string() })),
|
|
850
|
+
exchanges: z5.array(z5.object({ name: z5.string() }))
|
|
851
|
+
});
|
|
852
|
+
z5.object({
|
|
853
|
+
tradelinkId: z5.string(),
|
|
854
|
+
workspaceName: zWorkspaceName,
|
|
855
|
+
custodian: zTradelinkOrgEntityResponse,
|
|
856
|
+
assetManagers: z5.array(zTradelinkOrgEntityResponse),
|
|
857
|
+
exchanges: z5.array(zTradelinkOrgEntityResponse)
|
|
858
|
+
});
|
|
859
|
+
var zTradelinkAsset = z5.object({
|
|
860
|
+
name: z5.string(),
|
|
861
|
+
magnitude: z5.number().int().nonnegative()
|
|
862
|
+
});
|
|
863
|
+
z5.object({
|
|
864
|
+
tradelinkId: zTradelinkId,
|
|
865
|
+
asset: zTradelinkAsset,
|
|
866
|
+
state: z5.enum([
|
|
867
|
+
"PLEDGE_READY",
|
|
868
|
+
"PLEDGE_INCREMENT_PENDING_APPROVAL",
|
|
869
|
+
"PLEDGE_APPROVED",
|
|
870
|
+
"PLEDGE_REJECTED",
|
|
871
|
+
"UNPLEDGE_PENDING_APPROVAL",
|
|
872
|
+
"UNPLEDGE_APPROVED",
|
|
873
|
+
"UNPLEDGE_REJECTED",
|
|
874
|
+
"REPLEDGE_PENDING_APPROVAL",
|
|
875
|
+
"REPLEDGE_APPROVED",
|
|
876
|
+
"REPLEDGE_REJECTED",
|
|
877
|
+
"ASSIGNED_TO_SETTLEMENT",
|
|
878
|
+
"OUTBOUND_TRANSACTION_CONFIRMED",
|
|
879
|
+
"OUTBOUND_TRANSACTION_FAILED",
|
|
880
|
+
"RECOVERING_FROM_FAILURE",
|
|
881
|
+
"PLEDGE_CONSUMED"
|
|
882
|
+
]),
|
|
883
|
+
isLocked: z5.boolean(),
|
|
884
|
+
amount: z5.string().describe("Currently pledged amount"),
|
|
885
|
+
pending: z5.string().describe("Requested pledge increment, not yet approved"),
|
|
886
|
+
repledge: z5.string().describe("TODO: describe this field"),
|
|
887
|
+
exchangeTradelinkId: z5.string(),
|
|
888
|
+
accountId: z5.string()
|
|
889
|
+
});
|
|
890
|
+
z5.object({
|
|
891
|
+
workspaceName: z5.string(),
|
|
892
|
+
clientAccountId: z5.string().describe("Account ID from the client side"),
|
|
893
|
+
exchangeTradelinkId: zTradelinkId,
|
|
894
|
+
asset: zTradelinkAsset
|
|
895
|
+
});
|
|
896
|
+
z5.object({
|
|
897
|
+
pledgeTradelinkId: zTradelinkId,
|
|
898
|
+
amount: zBigInt,
|
|
899
|
+
asset: zTradelinkAsset
|
|
900
|
+
});
|
|
901
|
+
z5.object({
|
|
902
|
+
tradelinkId: z5.string(),
|
|
903
|
+
pledgeTradelinkId: z5.string(),
|
|
904
|
+
state: z5.enum([
|
|
905
|
+
"REGISTERED",
|
|
906
|
+
"PENDING_REPLEDGE_CREATION_APPROVAL",
|
|
907
|
+
"PENDING_REPLEDGE_APPROVAL",
|
|
908
|
+
"PENDING_CREATION_APPROVAL",
|
|
909
|
+
"PENDING_PRE_APPROVAL",
|
|
910
|
+
"PRE_APPROVED",
|
|
911
|
+
"APPROVED",
|
|
912
|
+
"REJECTED",
|
|
913
|
+
"CONFIRMED",
|
|
914
|
+
"FAILED"
|
|
915
|
+
]),
|
|
916
|
+
// For now we only consider the outbound settlement
|
|
917
|
+
outboundTransactionHash: z5.string().nullable()
|
|
918
|
+
});
|
|
919
|
+
|
|
920
|
+
// src/tradelink/request-data.ts
|
|
921
|
+
var zCustodianRequestData = z5.object({
|
|
922
|
+
settlement: zReviewStepWithUsersArray.describe("List of settlement review steps"),
|
|
923
|
+
withdraw: zReviewStepWithUsersArray.describe("List of withdraw review steps"),
|
|
924
|
+
arbitration: zReviewStepWithUsersArray.describe("List of arbitration review steps")
|
|
925
|
+
});
|
|
926
|
+
var zTradelinkEntityRequestData = z5.object({
|
|
927
|
+
tradelinkId: z5.string().min(1),
|
|
928
|
+
groups: zReviewStepWithUsersArray.describe("List of asset manager review groups"),
|
|
929
|
+
whitelist: z5.array(zTradelinkWhitelistAddress).describe("List of asset manager whitelisted addresses")
|
|
930
|
+
});
|
|
931
|
+
var zAdjustPledgeRequestData = z5.object({
|
|
932
|
+
accountId: z5.string().describe("Account id"),
|
|
933
|
+
exchangeId: z5.string().describe("Exchange id"),
|
|
934
|
+
amount: zIntString.describe("Amount to add to pledge")
|
|
935
|
+
});
|
|
936
|
+
var zCreateSettlementRequestData = z5.object({
|
|
937
|
+
accountId: z5.string().describe("Account id"),
|
|
938
|
+
exchangeId: z5.string().describe("Exchange id"),
|
|
939
|
+
transaction: zSendOnlyTransactionData
|
|
940
|
+
});
|
|
941
|
+
var zForceUnpledgeRequestData = z5.object({
|
|
942
|
+
accountId: z5.string().describe("Account id"),
|
|
943
|
+
exchangeId: z5.string().describe("Exchange id")
|
|
944
|
+
});
|
|
945
|
+
var zTradelinkWithdrawRequestData = z5.object({
|
|
946
|
+
accountId: z5.string().describe("Account id"),
|
|
947
|
+
transaction: zSendOnlyTransactionData
|
|
948
|
+
});
|
|
949
|
+
|
|
950
|
+
// src/accounts/account-governance-fields.ts
|
|
951
|
+
var zClassicAccountGovernanceFields = z.object({
|
|
952
|
+
type: z.literal(AccountGovernanceType.CLASSIC).describe("Classic account governance"),
|
|
953
|
+
policyId: z.string().describe("Identifier of corresponding governance policy")
|
|
954
|
+
}).describe("Classic");
|
|
955
|
+
var zTradelinkAccountGovernanceFields = z.object({
|
|
956
|
+
type: z.literal(AccountGovernanceType.TRADELINK).describe("Tradelink account governance"),
|
|
957
|
+
assetManagerId: z.string().describe("Identifier of corresponding asset manager"),
|
|
958
|
+
exchangeConfigs: zTradelinkExchangeConfigs.describe("Tradelink exchange configurations")
|
|
959
|
+
}).describe("Tradelink");
|
|
960
|
+
var zAccountGovernanceFields = z.discriminatedUnion("type", [zClassicAccountGovernanceFields, zTradelinkAccountGovernanceFields]).describe("Governance fields");
|
|
961
|
+
|
|
962
|
+
// src/accounts/types.ts
|
|
963
|
+
var zAccountCommonFields = z5.object({
|
|
964
|
+
id: z5.string().describe("Internal unique identifier"),
|
|
965
|
+
legacyId: z5.number().describe("Legacy internal unique identifier (for retro-compatibility)"),
|
|
966
|
+
status: z5.nativeEnum(ActivationStatus).describe("Status"),
|
|
967
|
+
name: z5.string().describe("Name"),
|
|
968
|
+
currency: z5.string().describe("Currency identifier"),
|
|
969
|
+
index: z5.number().gte(0).describe("BIP44 account index"),
|
|
970
|
+
derivationPath: z5.string().describe("Derivation path"),
|
|
971
|
+
createdAt: z5.coerce.date().describe("Creation timestamp"),
|
|
972
|
+
updatedAt: z5.coerce.date().describe("Last modification timestamp")
|
|
973
|
+
});
|
|
974
|
+
var zAccountBalanceFields = z5.object({
|
|
975
|
+
total: z5.string().describe("Total balance"),
|
|
976
|
+
pending: z5.string().describe("Pending balance")
|
|
977
|
+
}).describe("Balance fields");
|
|
978
|
+
var zAccountResponse = zAccountCommonFields.extend({
|
|
979
|
+
balance: zAccountBalanceFields.optional(),
|
|
980
|
+
asset: zAccountAssetFields,
|
|
981
|
+
governance: zAccountGovernanceFields
|
|
982
|
+
});
|
|
983
|
+
z5.enum([
|
|
984
|
+
"name",
|
|
985
|
+
"currency",
|
|
986
|
+
"index",
|
|
987
|
+
"createdAt",
|
|
988
|
+
"updatedAt"
|
|
989
|
+
]).default("createdAt");
|
|
990
|
+
|
|
991
|
+
// src/accounts/app-types.ts
|
|
992
|
+
var zNote2 = z5.object({
|
|
993
|
+
title: z5.string().describe("Transaction note title"),
|
|
994
|
+
content: z5.string().describe("Transaction note content")
|
|
995
|
+
}).describe("Optional transaction note");
|
|
996
|
+
z5.discriminatedUnion(
|
|
997
|
+
zTransactionResponse.discriminator,
|
|
998
|
+
ensureNonEmptyArray(
|
|
999
|
+
zTransactionResponse.options.map((_) => _.extend({ note: zNote2.nullable() }))
|
|
1000
|
+
)
|
|
1001
|
+
);
|
|
1002
|
+
var zWhitelistAddress = z5.object({
|
|
1003
|
+
name: z5.string().min(1).max(50),
|
|
1004
|
+
currency: z5.string().min(1).max(50),
|
|
1005
|
+
address: z5.string().min(1).max(200),
|
|
1006
|
+
// Destination tags are numeric-only or alpha-numeric.
|
|
1007
|
+
// Empty array (or undefined) means no check on destination tag.
|
|
1008
|
+
destinationTags: z5.array(z5.string().min(1).regex(/^\w+$/)).optional()
|
|
1009
|
+
});
|
|
1010
|
+
var zWhitelistAddresses = z5.array(zWhitelistAddress);
|
|
1011
|
+
var zWhitelistName = z5.string().min(1).max(45).describe("Whitelist name");
|
|
1012
|
+
var zCreateWhitelistRequestData = z5.object({
|
|
1013
|
+
name: zWhitelistName,
|
|
1014
|
+
description: z5.string().nullable(),
|
|
1015
|
+
addresses: zWhitelistAddresses,
|
|
1016
|
+
type: z5.nativeEnum(WhitelistType)
|
|
1017
|
+
});
|
|
1018
|
+
var zEditWhitelistRequestData = z5.object({
|
|
1019
|
+
name: zWhitelistName,
|
|
1020
|
+
addresses: zWhitelistAddresses
|
|
1021
|
+
});
|
|
1022
|
+
|
|
1023
|
+
// src/policies/db-utils.ts
|
|
1024
|
+
var zThreshold = z5.object({
|
|
1025
|
+
min: z5.string().regex(/^\d+$/).nullable().describe("Minimum transaction amount"),
|
|
1026
|
+
// bigint
|
|
1027
|
+
max: z5.string().regex(/^\d+$/).nullable().describe("Maximum transaction amount")
|
|
1028
|
+
// bigint
|
|
1029
|
+
}).describe("Threshold for the transaction value");
|
|
1030
|
+
var zWhitelistIds = z5.array(z5.string().min(1)).describe("IDs of whitelists for the recipient address");
|
|
1031
|
+
var zGovRuleJsonObject = z5.object({
|
|
1032
|
+
// Required.
|
|
1033
|
+
operationType: zOperationType.describe("Allowed operation type"),
|
|
1034
|
+
// Optional threshold on transaction value: null `min` = 0, null `max` = +inf
|
|
1035
|
+
threshold: zThreshold,
|
|
1036
|
+
// Optional whitelist on transaction recipient: Empty list means no whitelist.
|
|
1037
|
+
whitelistIds: zWhitelistIds,
|
|
1038
|
+
reviewConfigId: z5.string().min(1).describe("Id of ReviewConfig"),
|
|
1039
|
+
// HSM id for the rule
|
|
1040
|
+
hsmId: zHsmObjectId
|
|
1041
|
+
}).describe("INTERNAL: Governance rule JSON representation in DB");
|
|
1042
|
+
z5.array(zGovRuleJsonObject);
|
|
1043
|
+
var zAccountGovRuleData = z5.object({
|
|
1044
|
+
operationType: zAccountOperationType.describe("Allowed operation type"),
|
|
1045
|
+
// Optional threshold on transaction value: null `min` = 0, null `max` = +inf
|
|
1046
|
+
threshold: zThreshold.optional(),
|
|
1047
|
+
// Optional whitelist on transaction recipient: Empty list means no whitelist.
|
|
1048
|
+
whitelistIds: zWhitelistIds.optional(),
|
|
1049
|
+
reviewSteps: zReviewStepsArray
|
|
1050
|
+
}).describe("Account governance rule");
|
|
1051
|
+
var zGovRuleData = z5.discriminatedUnion("operationType", [zAccountGovRuleData]).describe("Governance rule");
|
|
1052
|
+
var zPolicyName = z5.string().min(1).max(19).describe("Policy name");
|
|
1053
|
+
var zCurrency = z5.string().min(1).max(40).regex(/^\w+$/).describe("Currency");
|
|
1054
|
+
var zCreatePolicyRequestData = z5.object({
|
|
1055
|
+
name: zPolicyName,
|
|
1056
|
+
description: z5.string().nullable().describe("Description"),
|
|
1057
|
+
currency: zCurrency,
|
|
1058
|
+
govRules: z5.array(zGovRuleData).describe("Governance rules")
|
|
1059
|
+
});
|
|
1060
|
+
var zEditPolicyRequestData = z5.object({
|
|
1061
|
+
name: zPolicyName,
|
|
1062
|
+
description: z5.string().nullable().describe("Description"),
|
|
1063
|
+
govRules: z5.array(zGovRuleData).describe("Governance rules")
|
|
1064
|
+
});
|
|
1065
|
+
|
|
1066
|
+
// src/accounts/request-data.ts
|
|
1067
|
+
var zAccountName = z5.string().min(1).max(40).describe("Account name");
|
|
1068
|
+
var zCurrency2 = z5.string().min(1).max(40).regex(/^\w+$/).describe("Currency");
|
|
1069
|
+
var zAccountPolicyRequestData = z5.discriminatedUnion("type", [
|
|
1070
|
+
z5.object({ type: z5.literal(PolicyType.ACCOUNT_POLICY), policyId: z5.string() }).describe("Account policy"),
|
|
1071
|
+
z5.object({ type: z5.literal(PolicyType.ACCOUNT_PRIVATE_POLICY), rules: z5.array(zGovRuleData) }).describe("Account governance rules")
|
|
1072
|
+
]).describe("Account policy or governance rules");
|
|
1073
|
+
var zCreateAccountGovernanceData = z5.discriminatedUnion("type", [
|
|
1074
|
+
z5.object({
|
|
1075
|
+
type: z5.literal(AccountGovernanceType.CLASSIC),
|
|
1076
|
+
policy: zAccountPolicyRequestData
|
|
1077
|
+
}),
|
|
1078
|
+
z5.object({
|
|
1079
|
+
type: z5.literal(AccountGovernanceType.TRADELINK),
|
|
1080
|
+
assetManagerId: z5.string(),
|
|
1081
|
+
exchangeConfigs: zTradelinkExchangeConfigs
|
|
1082
|
+
})
|
|
1083
|
+
]);
|
|
1084
|
+
var zCreateAccountUserInputData = z5.object({
|
|
1085
|
+
name: zAccountName,
|
|
1086
|
+
type: z5.nativeEnum(AccountType),
|
|
1087
|
+
// "BITCOIN_LIKE"
|
|
1088
|
+
currency: zCurrency2,
|
|
1089
|
+
// "bitcoin"
|
|
1090
|
+
index: z5.number().nonnegative().optional().describe("Account index"),
|
|
1091
|
+
contractAddress: z5.string().min(1).optional().describe("Account contract address"),
|
|
1092
|
+
governance: zCreateAccountGovernanceData
|
|
1093
|
+
});
|
|
1094
|
+
var zCreateAccountRequestData = zCreateAccountUserInputData.omit({ index: true }).extend({
|
|
1095
|
+
index: z5.number().nonnegative().describe("Account index"),
|
|
1096
|
+
derivationPath: z5.string().describe("Account bip44 derivation path")
|
|
1097
|
+
});
|
|
1098
|
+
var zEditAccountGovernanceData = z5.discriminatedUnion("type", [
|
|
1099
|
+
z5.object({
|
|
1100
|
+
type: z5.literal(AccountGovernanceType.CLASSIC),
|
|
1101
|
+
policy: zAccountPolicyRequestData
|
|
1102
|
+
}),
|
|
1103
|
+
z5.object({
|
|
1104
|
+
type: z5.literal(AccountGovernanceType.TRADELINK),
|
|
1105
|
+
exchangeConfigs: zTradelinkExchangeConfigs
|
|
1106
|
+
})
|
|
1107
|
+
]);
|
|
1108
|
+
var zEditAccountRequestData = z5.object({
|
|
1109
|
+
name: zAccountName,
|
|
1110
|
+
governance: zEditAccountGovernanceData
|
|
1111
|
+
});
|
|
1112
|
+
var zActivateAccountRequestData = z5.object({});
|
|
1113
|
+
var zEditTokenRuleRequestData = z5.object({
|
|
1114
|
+
parentAccountId: z5.string().min(1).describe("Parent account unique ID"),
|
|
1115
|
+
contractAddress: z5.string().min(1).describe("Token contract address"),
|
|
1116
|
+
rules: z5.array(zGovRuleData).describe("Account governance rules")
|
|
1117
|
+
});
|
|
1118
|
+
|
|
1119
|
+
// src/accounts/app-utils.ts
|
|
1120
|
+
var getAccountAssetStaticFields = (account) => {
|
|
1121
|
+
switch (account.type) {
|
|
1122
|
+
case AccountType.BITCOIN_LIKE:
|
|
1123
|
+
return {
|
|
1124
|
+
type: account.type,
|
|
1125
|
+
xpub: account.xpub
|
|
1126
|
+
};
|
|
1127
|
+
case AccountType.ETHEREUM_LIKE:
|
|
1128
|
+
return {
|
|
1129
|
+
type: account.type,
|
|
1130
|
+
address: account.address
|
|
1131
|
+
};
|
|
1132
|
+
case AccountType.ERC20_LIKE:
|
|
1133
|
+
case AccountType.BEP20_LIKE:
|
|
1134
|
+
case AccountType.TRC20_LIKE:
|
|
1135
|
+
return {
|
|
1136
|
+
type: account.type,
|
|
1137
|
+
address: account.address,
|
|
1138
|
+
contractAddress: account.contractAddress
|
|
1139
|
+
};
|
|
1140
|
+
case AccountType.CARDANO_LIKE:
|
|
1141
|
+
return {
|
|
1142
|
+
type: account.type,
|
|
1143
|
+
address: account.address
|
|
1144
|
+
};
|
|
1145
|
+
case AccountType.SOLANA_LIKE:
|
|
1146
|
+
return {
|
|
1147
|
+
type: account.type,
|
|
1148
|
+
address: account.address,
|
|
1149
|
+
contractAddress: account.contractAddress
|
|
1150
|
+
};
|
|
1151
|
+
case AccountType.TEZOS_LIKE:
|
|
1152
|
+
return {
|
|
1153
|
+
type: account.type,
|
|
1154
|
+
address: account.address
|
|
1155
|
+
};
|
|
1156
|
+
case AccountType.STELLAR_LIKE:
|
|
1157
|
+
return {
|
|
1158
|
+
type: account.type,
|
|
1159
|
+
address: account.address
|
|
1160
|
+
};
|
|
1161
|
+
case AccountType.RIPPLE_LIKE:
|
|
1162
|
+
return {
|
|
1163
|
+
type: account.type,
|
|
1164
|
+
xpub: account.xpub
|
|
1165
|
+
};
|
|
1166
|
+
case AccountType.POLKADOT_LIKE:
|
|
1167
|
+
return {
|
|
1168
|
+
type: account.type,
|
|
1169
|
+
address: account.address
|
|
1170
|
+
};
|
|
1171
|
+
case AccountType.GENERIC_LIKE:
|
|
1172
|
+
return {
|
|
1173
|
+
type: account.type
|
|
1174
|
+
};
|
|
1175
|
+
/* v8 ignore start */
|
|
1176
|
+
default:
|
|
1177
|
+
unreachable(account.type);
|
|
1178
|
+
}
|
|
1179
|
+
};
|
|
1180
|
+
var getAccountGovernanceFields = (account) => {
|
|
1181
|
+
switch (account.governanceType) {
|
|
1182
|
+
case AccountGovernanceType.CLASSIC:
|
|
1183
|
+
return {
|
|
1184
|
+
type: AccountGovernanceType.CLASSIC,
|
|
1185
|
+
policyId: account.classicGovernanceMixin.policyId
|
|
1186
|
+
};
|
|
1187
|
+
case AccountGovernanceType.TRADELINK:
|
|
1188
|
+
return {
|
|
1189
|
+
type: AccountGovernanceType.TRADELINK,
|
|
1190
|
+
assetManagerId: account.tradelinkGovernanceMixin.assetManagerId,
|
|
1191
|
+
exchangeConfigs: zTradelinkExchangeConfigs.parse(
|
|
1192
|
+
account.tradelinkGovernanceMixin.exchangeConfigs
|
|
1193
|
+
)
|
|
1194
|
+
};
|
|
1195
|
+
/* v8 ignore start */
|
|
1196
|
+
default:
|
|
1197
|
+
unreachable(account.governanceType);
|
|
1198
|
+
}
|
|
1199
|
+
};
|
|
1200
|
+
var serializeAccount = (account) => {
|
|
1201
|
+
const asset = getAccountAssetStaticFields(account);
|
|
1202
|
+
const governance = getAccountGovernanceFields(account);
|
|
1203
|
+
const response = {
|
|
1204
|
+
...account,
|
|
1205
|
+
legacyId: account.gateId,
|
|
1206
|
+
governance,
|
|
1207
|
+
asset
|
|
1208
|
+
};
|
|
1209
|
+
return zAccountResponse.parse(response);
|
|
1210
|
+
};
|
|
1211
|
+
var zSciConfigData = z5.object({
|
|
1212
|
+
dapps: z5.array(z5.string()).nullable().describe("Allowed DApps, null allows all"),
|
|
1213
|
+
customContractCallEnabled: z5.boolean().describe("Allow non-DApp SCI")
|
|
1214
|
+
});
|
|
1215
|
+
var zCreateSciConfigRequestData = z5.object({
|
|
1216
|
+
account: z5.string().describe("Account UUID"),
|
|
1217
|
+
config: zSciConfigData
|
|
1218
|
+
});
|
|
1219
|
+
var zEditSciConfigRequestData = z5.object({
|
|
1220
|
+
config: zSciConfigData
|
|
1221
|
+
});
|
|
1222
|
+
var zRequestReviewStep = z.object({
|
|
1223
|
+
stageName: z.string().regex(/^\w+$/).describe("The review stage name"),
|
|
1224
|
+
quorum: z.number().int().min(1).describe("Quorum for the review step")
|
|
1225
|
+
});
|
|
1226
|
+
var zRequestReviewSteps = z.array(zRequestReviewStep);
|
|
1227
|
+
var zGroupName = z5.string().min(1).max(19).describe("Group name");
|
|
1228
|
+
var zCreateGroupRequestData = z5.object({
|
|
1229
|
+
name: zGroupName,
|
|
1230
|
+
description: z5.string().nullable().describe("Group description"),
|
|
1231
|
+
members: z5.array(z5.string()).describe("List of group members ids")
|
|
1232
|
+
});
|
|
1233
|
+
var zEditGroupRequestData = z5.object({
|
|
1234
|
+
name: zGroupName,
|
|
1235
|
+
members: z5.array(z5.string()).describe("List of group members ids")
|
|
1236
|
+
});
|
|
1237
|
+
var zRegistration = z5.discriminatedUnion("subState", [
|
|
1238
|
+
z5.object({
|
|
1239
|
+
subState: z5.literal("PENDING"),
|
|
1240
|
+
deviceData: zUserRegistrationDeviceData.describe("Device data"),
|
|
1241
|
+
challenge: zUserRegistrationChallenge.describe("Registration challenge")
|
|
1242
|
+
}).describe("Pending registration"),
|
|
1243
|
+
z5.object({
|
|
1244
|
+
subState: z5.literal("COMPLETED"),
|
|
1245
|
+
pubKey: zPubKey.describe("User device public key"),
|
|
1246
|
+
u2fKeyHandle: z5.string().describe("U2F key handle for authenticate via PSD"),
|
|
1247
|
+
u2fPubKey: zPubKey.describe("U2F public key for authenticate via PSD")
|
|
1248
|
+
}).describe("Completed registration")
|
|
1249
|
+
]);
|
|
1250
|
+
var zUserName = z5.string().min(1).max(19).describe("User name");
|
|
1251
|
+
var zCreateUserWithDeviceData = z5.object({
|
|
1252
|
+
name: zUserName,
|
|
1253
|
+
deviceType: z5.enum([UserDeviceType.PSD, UserDeviceType.SOFT_PSD]).describe("Device type"),
|
|
1254
|
+
deviceUserId: z5.string().regex(/^[A-F0-9]{16}$/).describe("Device user ID"),
|
|
1255
|
+
registration: zRegistration.optional().describe("Data collected from the new user during registration")
|
|
1256
|
+
}).describe("Create PSD or Soft PSD user request data");
|
|
1257
|
+
var zCreateAdminRequestData = zCreateUserWithDeviceData.extend({
|
|
1258
|
+
deviceType: z5.literal(UserDeviceType.PSD).describe("Device type")
|
|
1259
|
+
// Admin must use PSD
|
|
1260
|
+
});
|
|
1261
|
+
var zCreateOperatorRequestData = zCreateUserWithDeviceData;
|
|
1262
|
+
var zCreateApiUserRequestData = z5.object({
|
|
1263
|
+
name: zUserName,
|
|
1264
|
+
publicKey: z5.string().describe("Public key")
|
|
1265
|
+
}).describe("Create API user request data");
|
|
1266
|
+
var zCreateApiUserAccessRequestData = z5.object({
|
|
1267
|
+
name: zUserName
|
|
1268
|
+
}).describe("Create API user request data");
|
|
1269
|
+
var zApiKeyName = z5.string().min(1).max(19).describe("API key name");
|
|
1270
|
+
var zCreateApiKeyRequestData = z5.object({
|
|
1271
|
+
name: zApiKeyName,
|
|
1272
|
+
entities: z5.array(z5.string()).describe("List of related entities ids"),
|
|
1273
|
+
scopes: z5.object({}).describe("FIXME to be precised")
|
|
1274
|
+
}).describe("Create read-only API key request data");
|
|
1275
|
+
var zEditApiKeyRequestData = zCreateApiKeyRequestData.describe(
|
|
1276
|
+
"Edit read-only API key request data"
|
|
1277
|
+
);
|
|
1278
|
+
var zEntityName = z5.string().min(1).max(19).describe("Entity name");
|
|
1279
|
+
var zCreateEntityRequestData = z5.object({
|
|
1280
|
+
name: zEntityName,
|
|
1281
|
+
accounts: z5.array(z5.string())
|
|
1282
|
+
});
|
|
1283
|
+
var zEditEntityRequestData = z5.object({
|
|
1284
|
+
name: zEntityName,
|
|
1285
|
+
accounts: z5.array(z5.string())
|
|
1286
|
+
});
|
|
1287
|
+
var NonRootAdminPermission = omit(AdminPermission, "ROOT");
|
|
1288
|
+
var zWorkspaceRuleRequestData = z5.object({
|
|
1289
|
+
permission: z5.nativeEnum(NonRootAdminPermission).describe("Granted permissions"),
|
|
1290
|
+
reviewConfig: zReviewStepWithUsersArray.describe("List of admin review steps")
|
|
1291
|
+
});
|
|
1292
|
+
var zUpdateQuorumRequestData = z5.object({
|
|
1293
|
+
quorum: z5.number().int().min(1).describe("Workspace quorum")
|
|
1294
|
+
});
|
|
1295
|
+
|
|
1296
|
+
// src/requests/request-data.ts
|
|
1297
|
+
var zUserCreationVaultRequestMixinsByType = {
|
|
1298
|
+
CREATE_ADMIN: z5.object({
|
|
1299
|
+
type: z5.literal(RequestType.CREATE_ADMIN),
|
|
1300
|
+
data: zCreateAdminRequestData
|
|
1301
|
+
}),
|
|
1302
|
+
CREATE_OPERATOR: z5.object({
|
|
1303
|
+
type: z5.literal(RequestType.CREATE_OPERATOR),
|
|
1304
|
+
data: zCreateOperatorRequestData
|
|
1305
|
+
})
|
|
1306
|
+
};
|
|
1307
|
+
var zVaultRequestMixinsByType = {
|
|
1308
|
+
// Workspaces
|
|
1309
|
+
[RequestType.UPDATE_QUORUM]: z5.object({
|
|
1310
|
+
type: z5.literal(RequestType.UPDATE_QUORUM),
|
|
1311
|
+
data: zUpdateQuorumRequestData
|
|
1312
|
+
}),
|
|
1313
|
+
// Transactions
|
|
1314
|
+
[RequestType.CREATE_TRANSACTION]: z5.object({
|
|
1315
|
+
type: z5.literal(RequestType.CREATE_TRANSACTION),
|
|
1316
|
+
data: zCreateTransactionRequestData,
|
|
1317
|
+
meta: z5.object({
|
|
1318
|
+
hash: z5.string().nullable()
|
|
1319
|
+
}).optional().nullable()
|
|
1320
|
+
}),
|
|
1321
|
+
// Accounts
|
|
1322
|
+
[RequestType.CREATE_ACCOUNT]: z5.object({
|
|
1323
|
+
type: z5.literal(RequestType.CREATE_ACCOUNT),
|
|
1324
|
+
data: zCreateAccountRequestData
|
|
1325
|
+
}),
|
|
1326
|
+
[RequestType.EDIT_ACCOUNT]: z5.object({
|
|
1327
|
+
type: z5.literal(RequestType.EDIT_ACCOUNT),
|
|
1328
|
+
data: zEditAccountRequestData
|
|
1329
|
+
}),
|
|
1330
|
+
[RequestType.ACTIVATE_TRADELINK_ACCOUNT]: z5.object({
|
|
1331
|
+
type: z5.literal(RequestType.ACTIVATE_TRADELINK_ACCOUNT),
|
|
1332
|
+
targetId: z5.string(),
|
|
1333
|
+
data: zActivateAccountRequestData
|
|
1334
|
+
}),
|
|
1335
|
+
[RequestType.EDIT_TOKEN_RULE]: z5.object({
|
|
1336
|
+
type: z5.literal(RequestType.EDIT_TOKEN_RULE),
|
|
1337
|
+
targetId: z5.string(),
|
|
1338
|
+
data: zEditTokenRuleRequestData
|
|
1339
|
+
}),
|
|
1340
|
+
// Groups
|
|
1341
|
+
[RequestType.CREATE_GROUP]: z5.object({
|
|
1342
|
+
type: z5.literal(RequestType.CREATE_GROUP),
|
|
1343
|
+
data: zCreateGroupRequestData
|
|
1344
|
+
}),
|
|
1345
|
+
[RequestType.EDIT_GROUP]: z5.object({
|
|
1346
|
+
type: z5.literal(RequestType.EDIT_GROUP),
|
|
1347
|
+
data: zEditGroupRequestData
|
|
1348
|
+
}),
|
|
1349
|
+
[RequestType.REVOKE_GROUP]: z5.object({
|
|
1350
|
+
type: z5.literal(RequestType.REVOKE_GROUP),
|
|
1351
|
+
data: z5.object({})
|
|
1352
|
+
}),
|
|
1353
|
+
// Whitelists
|
|
1354
|
+
[RequestType.CREATE_WHITELIST]: z5.object({
|
|
1355
|
+
type: z5.literal(RequestType.CREATE_WHITELIST),
|
|
1356
|
+
data: zCreateWhitelistRequestData
|
|
1357
|
+
}),
|
|
1358
|
+
[RequestType.EDIT_WHITELIST]: z5.object({
|
|
1359
|
+
type: z5.literal(RequestType.EDIT_WHITELIST),
|
|
1360
|
+
data: zEditWhitelistRequestData
|
|
1361
|
+
}),
|
|
1362
|
+
// Entities
|
|
1363
|
+
[RequestType.CREATE_ENTITY]: z5.object({
|
|
1364
|
+
type: z5.literal(RequestType.CREATE_ENTITY),
|
|
1365
|
+
data: zCreateEntityRequestData
|
|
1366
|
+
}),
|
|
1367
|
+
[RequestType.EDIT_ENTITY]: z5.object({
|
|
1368
|
+
type: z5.literal(RequestType.EDIT_ENTITY),
|
|
1369
|
+
data: zEditEntityRequestData
|
|
1370
|
+
}),
|
|
1371
|
+
[RequestType.REVOKE_ENTITY]: z5.object({
|
|
1372
|
+
type: z5.literal(RequestType.REVOKE_ENTITY),
|
|
1373
|
+
data: z5.object({})
|
|
1374
|
+
}),
|
|
1375
|
+
// Users
|
|
1376
|
+
...zUserCreationVaultRequestMixinsByType,
|
|
1377
|
+
[RequestType.CREATE_API_USER]: z5.object({
|
|
1378
|
+
type: z5.literal(RequestType.CREATE_API_USER),
|
|
1379
|
+
data: zCreateApiUserRequestData
|
|
1380
|
+
}),
|
|
1381
|
+
[RequestType.CREATE_API_USER_ACCESS]: z5.object({
|
|
1382
|
+
type: z5.literal(RequestType.CREATE_API_USER_ACCESS),
|
|
1383
|
+
data: zCreateApiUserAccessRequestData
|
|
1384
|
+
}),
|
|
1385
|
+
[RequestType.REVOKE_USER]: z5.object({
|
|
1386
|
+
type: z5.literal(RequestType.REVOKE_USER),
|
|
1387
|
+
data: z5.object({})
|
|
1388
|
+
}),
|
|
1389
|
+
// Admin gov rules
|
|
1390
|
+
[RequestType.CREATE_WORKSPACE_RULE]: z5.object({
|
|
1391
|
+
type: z5.literal(RequestType.CREATE_WORKSPACE_RULE),
|
|
1392
|
+
data: zWorkspaceRuleRequestData
|
|
1393
|
+
}),
|
|
1394
|
+
[RequestType.EDIT_WORKSPACE_RULE]: z5.object({
|
|
1395
|
+
type: z5.literal(RequestType.EDIT_WORKSPACE_RULE),
|
|
1396
|
+
data: zWorkspaceRuleRequestData
|
|
1397
|
+
}),
|
|
1398
|
+
// SCI configs
|
|
1399
|
+
[RequestType.CREATE_SCICONFIG]: z5.object({
|
|
1400
|
+
type: z5.literal(RequestType.CREATE_SCICONFIG),
|
|
1401
|
+
data: zCreateSciConfigRequestData
|
|
1402
|
+
}),
|
|
1403
|
+
[RequestType.EDIT_SCICONFIG]: z5.object({
|
|
1404
|
+
type: z5.literal(RequestType.EDIT_SCICONFIG),
|
|
1405
|
+
data: zEditSciConfigRequestData
|
|
1406
|
+
}),
|
|
1407
|
+
// API keys
|
|
1408
|
+
[RequestType.CREATE_API_KEY]: z5.object({
|
|
1409
|
+
type: z5.literal(RequestType.CREATE_API_KEY),
|
|
1410
|
+
data: zCreateApiKeyRequestData
|
|
1411
|
+
}),
|
|
1412
|
+
[RequestType.EDIT_API_KEY]: z5.object({
|
|
1413
|
+
type: z5.literal(RequestType.EDIT_API_KEY),
|
|
1414
|
+
data: zEditApiKeyRequestData
|
|
1415
|
+
}),
|
|
1416
|
+
[RequestType.REVOKE_API_KEY]: z5.object({
|
|
1417
|
+
type: z5.literal(RequestType.REVOKE_API_KEY),
|
|
1418
|
+
data: z5.object({})
|
|
1419
|
+
}),
|
|
1420
|
+
// Policies
|
|
1421
|
+
[RequestType.CREATE_POLICY]: z5.object({
|
|
1422
|
+
type: z5.literal(RequestType.CREATE_POLICY),
|
|
1423
|
+
data: zCreatePolicyRequestData
|
|
1424
|
+
}),
|
|
1425
|
+
[RequestType.EDIT_POLICY]: z5.object({
|
|
1426
|
+
type: z5.literal(RequestType.EDIT_POLICY),
|
|
1427
|
+
data: zEditPolicyRequestData
|
|
1428
|
+
}),
|
|
1429
|
+
// Tradelink
|
|
1430
|
+
[RequestType.CREATE_TRADELINK_CUSTODIAN]: z5.object({
|
|
1431
|
+
type: z5.literal(RequestType.CREATE_TRADELINK_CUSTODIAN),
|
|
1432
|
+
data: zCustodianRequestData
|
|
1433
|
+
}),
|
|
1434
|
+
[RequestType.EDIT_TRADELINK_CUSTODIAN]: z5.object({
|
|
1435
|
+
type: z5.literal(RequestType.EDIT_TRADELINK_CUSTODIAN),
|
|
1436
|
+
targetId: z5.string(),
|
|
1437
|
+
data: zCustodianRequestData
|
|
1438
|
+
}),
|
|
1439
|
+
[RequestType.CREATE_TRADELINK_EXCHANGE]: z5.object({
|
|
1440
|
+
type: z5.literal(RequestType.CREATE_TRADELINK_EXCHANGE),
|
|
1441
|
+
data: zTradelinkEntityRequestData
|
|
1442
|
+
}),
|
|
1443
|
+
[RequestType.EDIT_TRADELINK_EXCHANGE]: z5.object({
|
|
1444
|
+
type: z5.literal(RequestType.EDIT_TRADELINK_EXCHANGE),
|
|
1445
|
+
targetId: z5.string(),
|
|
1446
|
+
data: zTradelinkEntityRequestData
|
|
1447
|
+
}),
|
|
1448
|
+
[RequestType.CREATE_TRADELINK_ASSET_MANAGER]: z5.object({
|
|
1449
|
+
type: z5.literal(RequestType.CREATE_TRADELINK_ASSET_MANAGER),
|
|
1450
|
+
data: zTradelinkEntityRequestData
|
|
1451
|
+
}),
|
|
1452
|
+
[RequestType.EDIT_TRADELINK_ASSET_MANAGER]: z5.object({
|
|
1453
|
+
type: z5.literal(RequestType.EDIT_TRADELINK_ASSET_MANAGER),
|
|
1454
|
+
targetId: z5.string(),
|
|
1455
|
+
data: zTradelinkEntityRequestData
|
|
1456
|
+
}),
|
|
1457
|
+
[RequestType.ADJUST_PLEDGE]: z5.object({
|
|
1458
|
+
type: z5.literal(RequestType.ADJUST_PLEDGE),
|
|
1459
|
+
data: zAdjustPledgeRequestData
|
|
1460
|
+
}),
|
|
1461
|
+
[RequestType.CREATE_SETTLEMENT]: z5.object({
|
|
1462
|
+
type: z5.literal(RequestType.CREATE_SETTLEMENT),
|
|
1463
|
+
data: zCreateSettlementRequestData
|
|
1464
|
+
}),
|
|
1465
|
+
[RequestType.FORCE_UNPLEDGE]: z5.object({
|
|
1466
|
+
type: z5.literal(RequestType.FORCE_UNPLEDGE),
|
|
1467
|
+
data: zForceUnpledgeRequestData
|
|
1468
|
+
}),
|
|
1469
|
+
[RequestType.TRADELINK_WITHDRAW]: z5.object({
|
|
1470
|
+
type: z5.literal(RequestType.TRADELINK_WITHDRAW),
|
|
1471
|
+
data: zTradelinkWithdrawRequestData
|
|
1472
|
+
}),
|
|
1473
|
+
// Deprecate ADMIN_GOV_RULE
|
|
1474
|
+
[RequestType.CREATE_ADMIN_GOV_RULE]: z5.object({
|
|
1475
|
+
type: z5.literal(RequestType.CREATE_ADMIN_GOV_RULE),
|
|
1476
|
+
data: z5.object({}).describe("Deprecated")
|
|
1477
|
+
}),
|
|
1478
|
+
[RequestType.EDIT_ADMIN_GOV_RULE]: z5.object({
|
|
1479
|
+
type: z5.literal(RequestType.EDIT_ADMIN_GOV_RULE),
|
|
1480
|
+
data: z5.object({}).describe("Deprecated")
|
|
1481
|
+
})
|
|
1482
|
+
};
|
|
1483
|
+
|
|
1484
|
+
// src/requests/app-types.ts
|
|
1485
|
+
var zRequestReviewResponse = z5.object({
|
|
1486
|
+
// Note: Do NOT include `quorum` as it is already available in the request's `reviewSteps` field.
|
|
1487
|
+
stepIndex: z5.number().int().describe("Index of the governance step in the request workflow"),
|
|
1488
|
+
userId: z5.string().describe("Reviewer id"),
|
|
1489
|
+
status: z5.nativeEnum(RequestReviewStatus).describe("Review status"),
|
|
1490
|
+
createdAt: z5.coerce.date().describe("Created date"),
|
|
1491
|
+
updatedAt: z5.coerce.date().describe("Updated date")
|
|
1492
|
+
});
|
|
1493
|
+
var zVaultRequestCommonMixin = z5.object({
|
|
1494
|
+
id: z5.string().describe("Request unique identifier"),
|
|
1495
|
+
legacyId: z5.number().describe("Legacy internal unique identifier (for retro-compatibility)"),
|
|
1496
|
+
state: z5.nativeEnum(RequestState).describe("Request state"),
|
|
1497
|
+
reviewSteps: zRequestReviewSteps.describe("Request review steps"),
|
|
1498
|
+
currentStepIndex: z5.number().int().min(0).describe("Index of the current approval step"),
|
|
1499
|
+
expiredAt: z5.coerce.date().nullable().describe("Optional expiration date"),
|
|
1500
|
+
targetId: z5.string().nullable().describe("Optional ID of the target object"),
|
|
1501
|
+
note: zNote.nullable().describe("Optional request note"),
|
|
1502
|
+
reviews: z5.array(zRequestReviewResponse).describe("Requests reviews"),
|
|
1503
|
+
// `type` and `data` are correlated -- See `zVaultRequestMixinsByType`
|
|
1504
|
+
createdAt: z5.coerce.date().describe("Creation timestamp"),
|
|
1505
|
+
updatedAt: z5.coerce.date().describe("Last modification timestamp")
|
|
1506
|
+
});
|
|
1507
|
+
var allowedRequestCreationInput = {
|
|
1508
|
+
[RequestType.CREATE_ADMIN]: zVaultRequestMixinsByType[RequestType.CREATE_ADMIN],
|
|
1509
|
+
[RequestType.CREATE_GROUP]: zVaultRequestMixinsByType[RequestType.CREATE_GROUP],
|
|
1510
|
+
[RequestType.CREATE_WHITELIST]: zVaultRequestMixinsByType[RequestType.CREATE_WHITELIST],
|
|
1511
|
+
[RequestType.EDIT_WHITELIST]: zVaultRequestMixinsByType[RequestType.EDIT_WHITELIST],
|
|
1512
|
+
[RequestType.CREATE_OPERATOR]: zVaultRequestMixinsByType[RequestType.CREATE_OPERATOR],
|
|
1513
|
+
[RequestType.CREATE_TRANSACTION]: zVaultRequestMixinsByType[RequestType.CREATE_TRANSACTION],
|
|
1514
|
+
[RequestType.CREATE_POLICY]: zVaultRequestMixinsByType[RequestType.CREATE_POLICY],
|
|
1515
|
+
[RequestType.EDIT_POLICY]: zVaultRequestMixinsByType[RequestType.EDIT_POLICY],
|
|
1516
|
+
[RequestType.CREATE_ACCOUNT]: z5.object({
|
|
1517
|
+
type: z5.literal(RequestType.CREATE_ACCOUNT),
|
|
1518
|
+
data: zCreateAccountUserInputData
|
|
1519
|
+
}),
|
|
1520
|
+
[RequestType.ACTIVATE_TRADELINK_ACCOUNT]: zVaultRequestMixinsByType[RequestType.ACTIVATE_TRADELINK_ACCOUNT],
|
|
1521
|
+
[RequestType.CREATE_TRADELINK_CUSTODIAN]: zVaultRequestMixinsByType[RequestType.CREATE_TRADELINK_CUSTODIAN],
|
|
1522
|
+
[RequestType.EDIT_TRADELINK_CUSTODIAN]: zVaultRequestMixinsByType[RequestType.EDIT_TRADELINK_CUSTODIAN],
|
|
1523
|
+
[RequestType.CREATE_TRADELINK_EXCHANGE]: zVaultRequestMixinsByType[RequestType.CREATE_TRADELINK_EXCHANGE],
|
|
1524
|
+
[RequestType.EDIT_TRADELINK_EXCHANGE]: zVaultRequestMixinsByType[RequestType.EDIT_TRADELINK_EXCHANGE],
|
|
1525
|
+
[RequestType.CREATE_TRADELINK_ASSET_MANAGER]: zVaultRequestMixinsByType[RequestType.CREATE_TRADELINK_ASSET_MANAGER],
|
|
1526
|
+
[RequestType.EDIT_TRADELINK_ASSET_MANAGER]: zVaultRequestMixinsByType[RequestType.EDIT_TRADELINK_ASSET_MANAGER],
|
|
1527
|
+
[RequestType.ADJUST_PLEDGE]: zVaultRequestMixinsByType[RequestType.ADJUST_PLEDGE],
|
|
1528
|
+
[RequestType.FORCE_UNPLEDGE]: zVaultRequestMixinsByType[RequestType.FORCE_UNPLEDGE],
|
|
1529
|
+
[RequestType.CREATE_SETTLEMENT]: zVaultRequestMixinsByType[RequestType.CREATE_SETTLEMENT],
|
|
1530
|
+
[RequestType.TRADELINK_WITHDRAW]: zVaultRequestMixinsByType[RequestType.TRADELINK_WITHDRAW]
|
|
1531
|
+
};
|
|
1532
|
+
z5.object({
|
|
1533
|
+
request: z5.discriminatedUnion(
|
|
1534
|
+
"type",
|
|
1535
|
+
ensureNonEmptyArray(
|
|
1536
|
+
Object.values(allowedRequestCreationInput).map((_) => {
|
|
1537
|
+
const requestType = _.shape.type._def.value;
|
|
1538
|
+
return _.describe(`${requestType} request data`);
|
|
1539
|
+
})
|
|
1540
|
+
)
|
|
1541
|
+
)
|
|
1542
|
+
});
|
|
1543
|
+
var zVaultRequestResponse = z5.discriminatedUnion(
|
|
1544
|
+
"type",
|
|
1545
|
+
ensureNonEmptyArray(
|
|
1546
|
+
Object.values(zVaultRequestMixinsByType).map((_) => {
|
|
1547
|
+
const requestType = _.shape.type._def.value;
|
|
1548
|
+
return _.merge(zVaultRequestCommonMixin).describe(`${requestType} request`);
|
|
1549
|
+
})
|
|
1550
|
+
)
|
|
1551
|
+
);
|
|
1552
|
+
z5.discriminatedUnion(
|
|
1553
|
+
"type",
|
|
1554
|
+
ensureNonEmptyArray(
|
|
1555
|
+
Object.values(zUserCreationVaultRequestMixinsByType).map((_) => {
|
|
1556
|
+
const requestType = _.shape.type._def.value;
|
|
1557
|
+
return _.merge(zVaultRequestCommonMixin).describe(`${requestType} request`);
|
|
1558
|
+
})
|
|
1559
|
+
)
|
|
1560
|
+
);
|
|
1561
|
+
z5.enum([
|
|
1562
|
+
"state",
|
|
1563
|
+
"expiredAt",
|
|
1564
|
+
"createdAt",
|
|
1565
|
+
"updatedAt"
|
|
1566
|
+
]).default("createdAt");
|
|
1567
|
+
z5.object({
|
|
1568
|
+
pubKey: z5.string().describe("Public key of the current user"),
|
|
1569
|
+
challenge: zUserChallenge.describe("Challenge data to sign with the user's private key")
|
|
1570
|
+
});
|
|
1571
|
+
var shouldHaveTargetHsmId = (request) => {
|
|
1572
|
+
switch (request.type) {
|
|
1573
|
+
case RequestType.CREATE_ENTITY:
|
|
1574
|
+
case RequestType.EDIT_ENTITY:
|
|
1575
|
+
case RequestType.REVOKE_ENTITY:
|
|
1576
|
+
case RequestType.CREATE_SCICONFIG:
|
|
1577
|
+
case RequestType.EDIT_SCICONFIG:
|
|
1578
|
+
case RequestType.CREATE_API_KEY:
|
|
1579
|
+
case RequestType.EDIT_API_KEY:
|
|
1580
|
+
case RequestType.REVOKE_API_KEY:
|
|
1581
|
+
case RequestType.CREATE_WORKSPACE_RULE:
|
|
1582
|
+
case RequestType.EDIT_WORKSPACE_RULE:
|
|
1583
|
+
return false;
|
|
1584
|
+
case RequestType.CREATE_ADMIN:
|
|
1585
|
+
case RequestType.CREATE_OPERATOR:
|
|
1586
|
+
if (request.state === RequestState.INITIAL || request.state === RequestState.PENDING_REGISTRATION) {
|
|
1587
|
+
return false;
|
|
1588
|
+
}
|
|
1589
|
+
if (request.state === RequestState.ABORTED || request.state === RequestState.BLOCKED || request.state === RequestState.EXPIRED) {
|
|
1590
|
+
return void 0;
|
|
1591
|
+
}
|
|
1592
|
+
return true;
|
|
1593
|
+
case RequestType.UPDATE_QUORUM:
|
|
1594
|
+
case RequestType.CREATE_TRANSACTION:
|
|
1595
|
+
case RequestType.CREATE_ACCOUNT:
|
|
1596
|
+
case RequestType.EDIT_ACCOUNT:
|
|
1597
|
+
case RequestType.ACTIVATE_TRADELINK_ACCOUNT:
|
|
1598
|
+
case RequestType.CREATE_GROUP:
|
|
1599
|
+
case RequestType.EDIT_GROUP:
|
|
1600
|
+
case RequestType.REVOKE_GROUP:
|
|
1601
|
+
case RequestType.CREATE_WHITELIST:
|
|
1602
|
+
case RequestType.EDIT_WHITELIST:
|
|
1603
|
+
case RequestType.CREATE_API_USER:
|
|
1604
|
+
case RequestType.CREATE_API_USER_ACCESS:
|
|
1605
|
+
// targeting / editing an existing `User`
|
|
1606
|
+
case RequestType.REVOKE_USER:
|
|
1607
|
+
case RequestType.CREATE_POLICY:
|
|
1608
|
+
case RequestType.EDIT_POLICY:
|
|
1609
|
+
case RequestType.CREATE_TRADELINK_CUSTODIAN:
|
|
1610
|
+
case RequestType.EDIT_TRADELINK_CUSTODIAN:
|
|
1611
|
+
case RequestType.CREATE_TRADELINK_EXCHANGE:
|
|
1612
|
+
case RequestType.EDIT_TRADELINK_EXCHANGE:
|
|
1613
|
+
case RequestType.CREATE_TRADELINK_ASSET_MANAGER:
|
|
1614
|
+
case RequestType.EDIT_TRADELINK_ASSET_MANAGER:
|
|
1615
|
+
return request.state !== RequestState.INITIAL;
|
|
1616
|
+
case RequestType.EDIT_TOKEN_RULE:
|
|
1617
|
+
return true;
|
|
1618
|
+
/* v8 ignore start */
|
|
1619
|
+
case RequestType.CREATE_ADMIN_GOV_RULE:
|
|
1620
|
+
case RequestType.EDIT_ADMIN_GOV_RULE:
|
|
1621
|
+
throw new Error(`Admin gov rules requests are deprecated`);
|
|
1622
|
+
}
|
|
1623
|
+
};
|
|
1624
|
+
var shouldHaveTargetId = (request) => {
|
|
1625
|
+
switch (request.type) {
|
|
1626
|
+
case RequestType.CREATE_API_KEY:
|
|
1627
|
+
case RequestType.EDIT_API_KEY:
|
|
1628
|
+
case RequestType.REVOKE_API_KEY:
|
|
1629
|
+
return false;
|
|
1630
|
+
case RequestType.CREATE_TRANSACTION:
|
|
1631
|
+
return false;
|
|
1632
|
+
case RequestType.CREATE_WORKSPACE_RULE:
|
|
1633
|
+
case RequestType.CREATE_ACCOUNT:
|
|
1634
|
+
case RequestType.CREATE_GROUP:
|
|
1635
|
+
case RequestType.CREATE_WHITELIST:
|
|
1636
|
+
case RequestType.CREATE_ENTITY:
|
|
1637
|
+
case RequestType.CREATE_ADMIN:
|
|
1638
|
+
case RequestType.CREATE_OPERATOR:
|
|
1639
|
+
case RequestType.CREATE_API_USER:
|
|
1640
|
+
case RequestType.CREATE_SCICONFIG:
|
|
1641
|
+
case RequestType.CREATE_POLICY:
|
|
1642
|
+
case RequestType.CREATE_TRADELINK_CUSTODIAN:
|
|
1643
|
+
case RequestType.CREATE_TRADELINK_EXCHANGE:
|
|
1644
|
+
case RequestType.CREATE_TRADELINK_ASSET_MANAGER:
|
|
1645
|
+
return request.state === RequestState.EXECUTED;
|
|
1646
|
+
case RequestType.UPDATE_QUORUM:
|
|
1647
|
+
case RequestType.EDIT_WORKSPACE_RULE:
|
|
1648
|
+
case RequestType.EDIT_ACCOUNT:
|
|
1649
|
+
case RequestType.ACTIVATE_TRADELINK_ACCOUNT:
|
|
1650
|
+
case RequestType.EDIT_TOKEN_RULE:
|
|
1651
|
+
// EDIT_TOKEN_RULE targetId is the parent account which must always exist, even when creating new token rule.
|
|
1652
|
+
case RequestType.EDIT_GROUP:
|
|
1653
|
+
case RequestType.REVOKE_GROUP:
|
|
1654
|
+
case RequestType.EDIT_WHITELIST:
|
|
1655
|
+
case RequestType.EDIT_ENTITY:
|
|
1656
|
+
case RequestType.REVOKE_ENTITY:
|
|
1657
|
+
case RequestType.CREATE_API_USER_ACCESS:
|
|
1658
|
+
case RequestType.REVOKE_USER:
|
|
1659
|
+
case RequestType.EDIT_SCICONFIG:
|
|
1660
|
+
case RequestType.EDIT_POLICY:
|
|
1661
|
+
case RequestType.EDIT_TRADELINK_CUSTODIAN:
|
|
1662
|
+
case RequestType.EDIT_TRADELINK_EXCHANGE:
|
|
1663
|
+
case RequestType.EDIT_TRADELINK_ASSET_MANAGER:
|
|
1664
|
+
case RequestType.ADJUST_PLEDGE:
|
|
1665
|
+
case RequestType.CREATE_SETTLEMENT:
|
|
1666
|
+
case RequestType.FORCE_UNPLEDGE:
|
|
1667
|
+
case RequestType.TRADELINK_WITHDRAW:
|
|
1668
|
+
return true;
|
|
1669
|
+
/* v8 ignore start */
|
|
1670
|
+
case RequestType.CREATE_ADMIN_GOV_RULE:
|
|
1671
|
+
case RequestType.EDIT_ADMIN_GOV_RULE:
|
|
1672
|
+
throw new Error(`Admin gov rules requests are deprecated`);
|
|
1673
|
+
}
|
|
1674
|
+
};
|
|
1675
|
+
|
|
1676
|
+
// src/requests/app-utils/index.ts
|
|
1677
|
+
function serializeVaultRequest(request) {
|
|
1678
|
+
const serialized = {
|
|
1679
|
+
...request,
|
|
1680
|
+
legacyId: request.gateId
|
|
1681
|
+
};
|
|
1682
|
+
if (request.type === "CREATE_TRANSACTION") {
|
|
1683
|
+
Object.assign(serialized, {
|
|
1684
|
+
meta: {
|
|
1685
|
+
hash: request.transactionMeta?.hash ?? null
|
|
1686
|
+
}
|
|
1687
|
+
});
|
|
1688
|
+
}
|
|
1689
|
+
return zVaultRequestResponse.parse(serialized);
|
|
1690
|
+
}
|
|
1691
|
+
var fakeHexString = (length, casing = "upper") => faker.string.hexadecimal({ prefix: "", casing, length });
|
|
1692
|
+
var fakePubKey = () => fakeHexString(130);
|
|
1693
|
+
var fakeIntegerId = () => faker.number.int({ min: 1, max: 2e9 });
|
|
1694
|
+
var fakeGateId = fakeIntegerId;
|
|
1695
|
+
var fakeBase64String = (length) => btoa(faker.string.sample(length));
|
|
1696
|
+
var fakePsdSignature = () => fakeBase64String(100);
|
|
1697
|
+
var fakeJws = () => times(3, () => faker.string.hexadecimal({ prefix: "", length: 100 })).join(".");
|
|
1698
|
+
var fakeHsmObjectId = () => faker.string.uuid();
|
|
1699
|
+
var fakeHsmCertificate = () => ({
|
|
1700
|
+
codeHash: fakeBase64String(10),
|
|
1701
|
+
attestationPub: fakeBase64String(20),
|
|
1702
|
+
certificate: fakeBase64String(20),
|
|
1703
|
+
signature: fakeBase64String(20)
|
|
1704
|
+
});
|
|
1705
|
+
var fakePsdChallenge = () => ({
|
|
1706
|
+
challengeType: "PSD",
|
|
1707
|
+
wActions: [fakeBase64String(50), fakeBase64String(50), fakeBase64String(50)],
|
|
1708
|
+
handshake: fakeBase64String(100),
|
|
1709
|
+
handshakeAttestation: fakeHsmCertificate(),
|
|
1710
|
+
partitionId: fakeBase64String(20)
|
|
1711
|
+
});
|
|
1712
|
+
var fakeWorkspaceName = () => faker.string.alpha({ length: 8, casing: "lower" });
|
|
1713
|
+
var injectSyncId = (obj) => {
|
|
1714
|
+
let { syncId } = obj;
|
|
1715
|
+
if (syncId === void 0) {
|
|
1716
|
+
if (obj.gateType !== null && obj.gateId !== 0) {
|
|
1717
|
+
syncId = buildGateSyncId(obj.workspaceName, obj.gateType, obj.gateId);
|
|
1718
|
+
} else if (obj.gateType === null && obj.gateId === 0) {
|
|
1719
|
+
syncId = faker.string.uuid();
|
|
1720
|
+
} else {
|
|
1721
|
+
throw new Error(`Invalid gateType and gateId: ${obj.gateType}, ${obj.gateId}`);
|
|
1722
|
+
}
|
|
1723
|
+
}
|
|
1724
|
+
return { ...obj, syncId };
|
|
1725
|
+
};
|
|
1726
|
+
var genAssetFieldsForType = (type) => {
|
|
1727
|
+
const hsmXpub = faker.string.hexadecimal({ prefix: "", casing: "upper", length: 66 });
|
|
1728
|
+
const hsmChainCode = faker.string.hexadecimal({ prefix: "", casing: "upper", length: 64 });
|
|
1729
|
+
switch (type) {
|
|
1730
|
+
case "BITCOIN_LIKE":
|
|
1731
|
+
return {
|
|
1732
|
+
type,
|
|
1733
|
+
currency: faker.helpers.arrayElement(["bitcoin", "bitcoin_testnet"]),
|
|
1734
|
+
derivationPath: "84'/0'/0'",
|
|
1735
|
+
address: null,
|
|
1736
|
+
contractAddress: null,
|
|
1737
|
+
xpub: faker.string.hexadecimal({ prefix: "", length: 120 }),
|
|
1738
|
+
hsmXpub,
|
|
1739
|
+
hsmChainCode
|
|
1740
|
+
};
|
|
1741
|
+
case "ETHEREUM_LIKE":
|
|
1742
|
+
// fall-through...
|
|
1743
|
+
case "ERC20_LIKE":
|
|
1744
|
+
case "BEP20_LIKE":
|
|
1745
|
+
return {
|
|
1746
|
+
type,
|
|
1747
|
+
currency: type === "BEP20_LIKE" ? "bsc" : faker.helpers.arrayElement(["ethereum", "ethereum_goerli"]),
|
|
1748
|
+
derivationPath: "44'/60'/0'",
|
|
1749
|
+
address: faker.finance.ethereumAddress(),
|
|
1750
|
+
contractAddress: type === "ETHEREUM_LIKE" ? null : faker.finance.ethereumAddress(),
|
|
1751
|
+
xpub: null,
|
|
1752
|
+
hsmXpub,
|
|
1753
|
+
hsmChainCode
|
|
1754
|
+
};
|
|
1755
|
+
case "CARDANO_LIKE":
|
|
1756
|
+
return {
|
|
1757
|
+
type,
|
|
1758
|
+
currency: faker.helpers.arrayElement(["cardano"]),
|
|
1759
|
+
derivationPath: "1852'/1815'/0'",
|
|
1760
|
+
address: `addr${faker.string.alphanumeric({ length: 100, casing: "lower" })}`,
|
|
1761
|
+
contractAddress: null,
|
|
1762
|
+
xpub: null,
|
|
1763
|
+
hsmXpub,
|
|
1764
|
+
hsmChainCode
|
|
1765
|
+
};
|
|
1766
|
+
case "SOLANA_LIKE":
|
|
1767
|
+
return {
|
|
1768
|
+
type,
|
|
1769
|
+
currency: faker.helpers.arrayElement(["solana"]),
|
|
1770
|
+
derivationPath: "44'/501'/0'",
|
|
1771
|
+
address: faker.string.alphanumeric({ length: 44, casing: "lower" }),
|
|
1772
|
+
contractAddress: null,
|
|
1773
|
+
xpub: null,
|
|
1774
|
+
hsmXpub,
|
|
1775
|
+
hsmChainCode: null
|
|
1776
|
+
};
|
|
1777
|
+
case "TEZOS_LIKE":
|
|
1778
|
+
return {
|
|
1779
|
+
type,
|
|
1780
|
+
currency: faker.helpers.arrayElement(["tezos"]),
|
|
1781
|
+
derivationPath: "44'/1729'/0'",
|
|
1782
|
+
address: `tz${faker.string.alphanumeric({ length: 34, casing: "mixed" })}`,
|
|
1783
|
+
contractAddress: null,
|
|
1784
|
+
xpub: null,
|
|
1785
|
+
hsmXpub,
|
|
1786
|
+
hsmChainCode
|
|
1787
|
+
};
|
|
1788
|
+
case "STELLAR_LIKE":
|
|
1789
|
+
return {
|
|
1790
|
+
type,
|
|
1791
|
+
currency: faker.helpers.arrayElement(["stellar"]),
|
|
1792
|
+
derivationPath: "44'/148'/0'",
|
|
1793
|
+
address: faker.string.alphanumeric({ length: 56, casing: "upper" }),
|
|
1794
|
+
contractAddress: null,
|
|
1795
|
+
xpub: null,
|
|
1796
|
+
hsmXpub,
|
|
1797
|
+
hsmChainCode
|
|
1798
|
+
};
|
|
1799
|
+
case "RIPPLE_LIKE":
|
|
1800
|
+
return {
|
|
1801
|
+
type,
|
|
1802
|
+
currency: faker.helpers.arrayElement(["ripple"]),
|
|
1803
|
+
derivationPath: "44'/144'/0'",
|
|
1804
|
+
address: faker.string.alphanumeric({ length: 34, casing: "mixed" }),
|
|
1805
|
+
contractAddress: null,
|
|
1806
|
+
xpub: `xpub${faker.string.alphanumeric({ length: 107, casing: "mixed" })}`,
|
|
1807
|
+
hsmXpub,
|
|
1808
|
+
hsmChainCode
|
|
1809
|
+
};
|
|
1810
|
+
case "POLKADOT_LIKE":
|
|
1811
|
+
return {
|
|
1812
|
+
type,
|
|
1813
|
+
currency: faker.helpers.arrayElement(["polkadot"]),
|
|
1814
|
+
derivationPath: "44'/354'/0'",
|
|
1815
|
+
address: faker.string.alphanumeric({ length: 48, casing: "mixed" }),
|
|
1816
|
+
contractAddress: null,
|
|
1817
|
+
xpub: null,
|
|
1818
|
+
hsmXpub,
|
|
1819
|
+
hsmChainCode: null
|
|
1820
|
+
};
|
|
1821
|
+
case "TRC20_LIKE":
|
|
1822
|
+
return {
|
|
1823
|
+
type,
|
|
1824
|
+
currency: faker.helpers.arrayElement(["tron"]),
|
|
1825
|
+
derivationPath: "44'/195'/0'",
|
|
1826
|
+
address: faker.string.alphanumeric({ length: 34, casing: "mixed" }),
|
|
1827
|
+
contractAddress: faker.string.alphanumeric({ length: 34, casing: "mixed" }),
|
|
1828
|
+
xpub: null,
|
|
1829
|
+
hsmXpub,
|
|
1830
|
+
hsmChainCode
|
|
1831
|
+
};
|
|
1832
|
+
case "GENERIC_LIKE":
|
|
1833
|
+
return {
|
|
1834
|
+
type,
|
|
1835
|
+
currency: faker.helpers.arrayElement(["cosmos"]),
|
|
1836
|
+
derivationPath: "44'/118'/0'",
|
|
1837
|
+
address: faker.string.alphanumeric({ length: 34, casing: "mixed" }),
|
|
1838
|
+
contractAddress: null,
|
|
1839
|
+
xpub: null,
|
|
1840
|
+
hsmXpub,
|
|
1841
|
+
hsmChainCode
|
|
1842
|
+
};
|
|
1843
|
+
}
|
|
1844
|
+
};
|
|
1845
|
+
var genGovernanceFieldsForType = (governanceType, {
|
|
1846
|
+
accountId,
|
|
1847
|
+
policyId,
|
|
1848
|
+
assetManagerId
|
|
1849
|
+
}) => {
|
|
1850
|
+
switch (governanceType) {
|
|
1851
|
+
case AccountGovernanceType.CLASSIC:
|
|
1852
|
+
return {
|
|
1853
|
+
governanceType,
|
|
1854
|
+
classicGovernanceMixin: {
|
|
1855
|
+
id: faker.number.int(),
|
|
1856
|
+
policyId: policyId ?? faker.string.uuid(),
|
|
1857
|
+
accountId
|
|
1858
|
+
},
|
|
1859
|
+
tradelinkGovernanceMixin: null
|
|
1860
|
+
};
|
|
1861
|
+
case AccountGovernanceType.TRADELINK:
|
|
1862
|
+
return {
|
|
1863
|
+
governanceType,
|
|
1864
|
+
classicGovernanceMixin: null,
|
|
1865
|
+
tradelinkGovernanceMixin: {
|
|
1866
|
+
id: faker.number.int(),
|
|
1867
|
+
assetManagerId: assetManagerId ?? faker.string.uuid(),
|
|
1868
|
+
accountId,
|
|
1869
|
+
exchangeConfigs: [],
|
|
1870
|
+
status: ActivationStatus.ACTIVE
|
|
1871
|
+
}
|
|
1872
|
+
};
|
|
1873
|
+
}
|
|
1874
|
+
};
|
|
1875
|
+
var genAccount = (opts) => {
|
|
1876
|
+
const { policyId, assetManagerId, ...rest } = opts ?? {};
|
|
1877
|
+
const commonFields = {
|
|
1878
|
+
id: faker.string.uuid(),
|
|
1879
|
+
workspaceName: fakeWorkspaceName(),
|
|
1880
|
+
name: faker.finance.accountName(),
|
|
1881
|
+
hsmId: fakeHsmObjectId(),
|
|
1882
|
+
status: ActivationStatus.ACTIVE,
|
|
1883
|
+
index: faker.number.int({ min: 0, max: 10 }),
|
|
1884
|
+
gateId: fakeGateId(),
|
|
1885
|
+
gateType: GateAccountType.Account,
|
|
1886
|
+
createdAt: faker.date.past(),
|
|
1887
|
+
updatedAt: faker.date.past()
|
|
1888
|
+
};
|
|
1889
|
+
const assetFields = genAssetFieldsForType(
|
|
1890
|
+
opts?.type ?? faker.helpers.arrayElement(Object.values(AccountType))
|
|
1891
|
+
);
|
|
1892
|
+
const governanceFields = genGovernanceFieldsForType(
|
|
1893
|
+
opts?.governanceType ?? faker.helpers.arrayElement(Object.values(AccountGovernanceType)),
|
|
1894
|
+
{ accountId: commonFields.id, policyId, assetManagerId }
|
|
1895
|
+
);
|
|
1896
|
+
return injectSyncId({
|
|
1897
|
+
...commonFields,
|
|
1898
|
+
...governanceFields,
|
|
1899
|
+
...assetFields,
|
|
1900
|
+
...rest
|
|
1901
|
+
});
|
|
1902
|
+
};
|
|
1903
|
+
var genRequestReviewSteps = (numSteps) => times(1, () => ({ stageName: "default", quorum: 2 }));
|
|
1904
|
+
var genVaultRequest = (opts) => {
|
|
1905
|
+
const { type, state = RequestState.PENDING_APPROVAL, data, ...custom } = opts;
|
|
1906
|
+
const targetHsmId = shouldHaveTargetHsmId({ type, state }) ? fakeHsmObjectId() : null;
|
|
1907
|
+
const targetId = shouldHaveTargetId({ type, state }) ? faker.string.uuid() : null;
|
|
1908
|
+
return injectSyncId({
|
|
1909
|
+
id: faker.string.uuid(),
|
|
1910
|
+
workspaceName: fakeWorkspaceName(),
|
|
1911
|
+
type,
|
|
1912
|
+
state,
|
|
1913
|
+
reviewSteps: genRequestReviewSteps(),
|
|
1914
|
+
currentStepIndex: 0,
|
|
1915
|
+
expiredAt: null,
|
|
1916
|
+
targetHsmId,
|
|
1917
|
+
createdById: faker.string.uuid(),
|
|
1918
|
+
createdAt: faker.date.past(),
|
|
1919
|
+
updatedAt: faker.date.past(),
|
|
1920
|
+
note: null,
|
|
1921
|
+
managedData: null,
|
|
1922
|
+
data,
|
|
1923
|
+
targetId,
|
|
1924
|
+
gateTargetType: "Whatsoever",
|
|
1925
|
+
gateTargetId: 0,
|
|
1926
|
+
gateType: "Request",
|
|
1927
|
+
gateId: fakeGateId(),
|
|
1928
|
+
// Note: Custom properties will overwrite the default ones. It is still possible for caller
|
|
1929
|
+
// to overwrite `targetId`. Thus it is not guaranteed that these values will always be
|
|
1930
|
+
// consistent with `type` and `state`.
|
|
1931
|
+
...custom
|
|
1932
|
+
});
|
|
1933
|
+
};
|
|
1934
|
+
var genVaultRequestReview = (opts) => {
|
|
1935
|
+
const status = opts?.status ?? RequestReviewStatus.PENDING;
|
|
1936
|
+
const challenge = opts?.challenge ?? fakePsdChallenge();
|
|
1937
|
+
const { challengeType } = challenge;
|
|
1938
|
+
let signature;
|
|
1939
|
+
if (status !== RequestReviewStatus.APPROVED) {
|
|
1940
|
+
signature = null;
|
|
1941
|
+
} else {
|
|
1942
|
+
switch (challengeType) {
|
|
1943
|
+
case ChallengeType.PSD:
|
|
1944
|
+
signature = fakePsdSignature();
|
|
1945
|
+
break;
|
|
1946
|
+
case ChallengeType.API:
|
|
1947
|
+
signature = fakeJws();
|
|
1948
|
+
break;
|
|
1949
|
+
}
|
|
1950
|
+
}
|
|
1951
|
+
return {
|
|
1952
|
+
id: faker.number.int(),
|
|
1953
|
+
requestId: faker.string.uuid(),
|
|
1954
|
+
stageName: "default",
|
|
1955
|
+
// assume the simple case where there is one single stage
|
|
1956
|
+
stepIndex: 0,
|
|
1957
|
+
userId: faker.string.uuid(),
|
|
1958
|
+
pubKey: fakePubKey(),
|
|
1959
|
+
challengeType,
|
|
1960
|
+
challenge,
|
|
1961
|
+
signature,
|
|
1962
|
+
status,
|
|
1963
|
+
createdAt: faker.date.past(),
|
|
1964
|
+
updatedAt: faker.date.past(),
|
|
1965
|
+
...opts
|
|
1966
|
+
};
|
|
1967
|
+
};
|
|
1968
|
+
|
|
1969
|
+
// src/__fakes__/responses.ts
|
|
1970
|
+
var genericBalanceFields = () => {
|
|
1971
|
+
const total = faker.number.int();
|
|
1972
|
+
const pending = faker.number.int({ min: 0, max: total / 2 });
|
|
1973
|
+
return {
|
|
1974
|
+
total: total.toString(),
|
|
1975
|
+
pending: pending.toString()
|
|
1976
|
+
};
|
|
1977
|
+
};
|
|
1978
|
+
var stakingFieldsByAccountType = {
|
|
1979
|
+
BEP20_LIKE: () => null,
|
|
1980
|
+
BITCOIN_LIKE: () => null,
|
|
1981
|
+
CARDANO_LIKE: () => ({
|
|
1982
|
+
type: "CARDANO_LIKE",
|
|
1983
|
+
staking: {
|
|
1984
|
+
staked: faker.number.int().toString()
|
|
1985
|
+
}
|
|
1986
|
+
}),
|
|
1987
|
+
ERC20_LIKE: () => null,
|
|
1988
|
+
ETHEREUM_LIKE: () => ({
|
|
1989
|
+
type: "ETHEREUM_LIKE",
|
|
1990
|
+
staking: {
|
|
1991
|
+
totalStaking: faker.number.int().toString(),
|
|
1992
|
+
totalRewards: faker.number.int().toString(),
|
|
1993
|
+
availableRewards: faker.number.int().toString(),
|
|
1994
|
+
networkApy: faker.number.float({ min: 0, max: 1 })
|
|
1995
|
+
}
|
|
1996
|
+
}),
|
|
1997
|
+
GENERIC_LIKE: () => null,
|
|
1998
|
+
POLKADOT_LIKE: () => ({
|
|
1999
|
+
type: "POLKADOT_LIKE",
|
|
2000
|
+
staking: {
|
|
2001
|
+
info: {
|
|
2002
|
+
controllerAddress: "<fake-controller-address>",
|
|
2003
|
+
rewardsDestination: "<fake-rewards-destination>",
|
|
2004
|
+
proxies: ["<fake-proxy>"],
|
|
2005
|
+
legacyStaking: false,
|
|
2006
|
+
isNominator: false
|
|
2007
|
+
},
|
|
2008
|
+
balances: {
|
|
2009
|
+
free: faker.number.int().toString(),
|
|
2010
|
+
reserved: faker.number.int().toString(),
|
|
2011
|
+
frozen: faker.number.int().toString(),
|
|
2012
|
+
bonded: faker.number.int().toString(),
|
|
2013
|
+
available: faker.number.int().toString(),
|
|
2014
|
+
unbonding: [{ amount: faker.number.int().toString(), waiting_time: "<fake-waiting-time>" }],
|
|
2015
|
+
unbonded: [{ amount: faker.number.int().toString(), waiting_time: "<fake-waiting-time>" }],
|
|
2016
|
+
totalUnbonding: faker.number.int().toString(),
|
|
2017
|
+
totalUnbonded: faker.number.int().toString()
|
|
2018
|
+
},
|
|
2019
|
+
anonymousProxy: {
|
|
2020
|
+
address: "<fake-anonymous-proxy-address>",
|
|
2021
|
+
createdAt: faker.date.past().toISOString(),
|
|
2022
|
+
isController: false,
|
|
2023
|
+
isMain: false,
|
|
2024
|
+
balances: {
|
|
2025
|
+
free: faker.number.int().toString(),
|
|
2026
|
+
reserved: faker.number.int().toString(),
|
|
2027
|
+
frozen: faker.number.int().toString(),
|
|
2028
|
+
bonded: faker.number.int().toString(),
|
|
2029
|
+
available: faker.number.int().toString(),
|
|
2030
|
+
total: faker.number.int().toString()
|
|
2031
|
+
},
|
|
2032
|
+
blockHeight: faker.number.int().toString(),
|
|
2033
|
+
extIndex: faker.number.int().toString(),
|
|
2034
|
+
index: faker.number.int().toString(),
|
|
2035
|
+
kind: "<fake-kind>"
|
|
2036
|
+
}
|
|
2037
|
+
}
|
|
2038
|
+
}),
|
|
2039
|
+
RIPPLE_LIKE: () => null,
|
|
2040
|
+
SOLANA_LIKE: () => ({
|
|
2041
|
+
type: "SOLANA_LIKE",
|
|
2042
|
+
staking: {
|
|
2043
|
+
staked: faker.number.int().toString(),
|
|
2044
|
+
rewards: {
|
|
2045
|
+
total: faker.number.int().toString(),
|
|
2046
|
+
last7: faker.number.int().toString(),
|
|
2047
|
+
last30: faker.number.int().toString()
|
|
2048
|
+
},
|
|
2049
|
+
stakes: [
|
|
2050
|
+
{
|
|
2051
|
+
uid: "<fake-stake-uid>",
|
|
2052
|
+
baseAccountUid: "<fake-base-account-uid>",
|
|
2053
|
+
pubKey: "<fake-pub-key>",
|
|
2054
|
+
validatorPubKey: "<fake-validator-pub-key>",
|
|
2055
|
+
initialAmount: faker.number.int().toString(),
|
|
2056
|
+
activeAmount: faker.number.int().toString(),
|
|
2057
|
+
inactiveAmount: faker.number.int().toString(),
|
|
2058
|
+
totalBalance: faker.number.int().toString(),
|
|
2059
|
+
creationDate: faker.date.past().toISOString(),
|
|
2060
|
+
activationEpoch: faker.date.past().toISOString(),
|
|
2061
|
+
activationDate: faker.date.past().toISOString(),
|
|
2062
|
+
deactivationEpoch: "<fake-deactivation-epoch>",
|
|
2063
|
+
deactivationDate: faker.date.past().toISOString(),
|
|
2064
|
+
status: "activated",
|
|
2065
|
+
rentExemptReserve: faker.number.int().toString(),
|
|
2066
|
+
withdrawableAmount: faker.number.int().toString(),
|
|
2067
|
+
totalRewards: faker.number.int().toString(),
|
|
2068
|
+
creationTxHash: "<fake-creation-tx-hash>",
|
|
2069
|
+
actionsTxHashes: ["<fake-action-tx-hash>"]
|
|
2070
|
+
}
|
|
2071
|
+
]
|
|
2072
|
+
}
|
|
2073
|
+
}),
|
|
2074
|
+
STELLAR_LIKE: () => null,
|
|
2075
|
+
TEZOS_LIKE: () => null,
|
|
2076
|
+
TRC20_LIKE: () => null
|
|
2077
|
+
};
|
|
2078
|
+
function genVaultRequestResponse(opts, reviews = []) {
|
|
2079
|
+
const request = genVaultRequest(opts);
|
|
2080
|
+
const requestWithReviews = { ...request, reviews };
|
|
2081
|
+
return serializeVaultRequest(requestWithReviews);
|
|
2082
|
+
}
|
|
2083
|
+
function genAccountResponse(overrides) {
|
|
2084
|
+
const dbAccount = genAccount(overrides);
|
|
2085
|
+
const account = serializeAccount(dbAccount);
|
|
2086
|
+
const staking = stakingFieldsByAccountType[account.asset.type]();
|
|
2087
|
+
Object.assign(account.asset, staking);
|
|
2088
|
+
const response = {
|
|
2089
|
+
...account,
|
|
2090
|
+
balance: genericBalanceFields()
|
|
2091
|
+
};
|
|
2092
|
+
return zAccountResponse.parse(response);
|
|
2093
|
+
}
|
|
2094
|
+
|
|
2095
|
+
export { genAccountResponse, genVaultRequestResponse, genVaultRequestReview };
|
|
2096
|
+
//# sourceMappingURL=fakes.mjs.map
|
|
2097
|
+
//# sourceMappingURL=fakes.mjs.map
|