@ledgerhq/revault-api 1.33.0 → 1.35.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/lib/fakes.mjs CHANGED
@@ -3,8 +3,8 @@ import { ChallengeType, PsdModel, AccountType, AccountGovernanceType, Activation
3
3
  import z7, { z } from 'zod';
4
4
  import 'axios';
5
5
  import invariant from 'invariant';
6
- import { omit, times } from 'lodash';
7
- import 'crypto';
6
+ import { omit, times, get, isPlainObject } from 'lodash';
7
+ import { randomUUID } from 'crypto';
8
8
 
9
9
  var __defProp = Object.defineProperty;
10
10
  var __export = (target, all) => {
@@ -72,6 +72,7 @@ var buildGateSyncId = (workspaceName, gateType, gateId) => {
72
72
  };
73
73
 
74
74
  // src/utils.ts
75
+ var isRecord = (value) => isPlainObject(value);
75
76
  var ensureNonEmptyArray = (values, message) => {
76
77
  invariant(
77
78
  values.length > 0,
@@ -243,6 +244,7 @@ var zTezosLikeTransactionType = z7.enum([
243
244
  "TEZOS_LIKE_UNDELEGATE"
244
245
  ]).describe("Tezos-like transaction type");
245
246
  var zGenericTransactionType = z7.enum(["GENERIC_TRANSACTION"]).describe("Generic transaction type");
247
+ var zSuiLikeTransactionType = z7.enum(["SUI_LIKE_SEND", "SUI_LIKE_RECEIVE", "SUI_LIKE_TRANSFER_TOKEN"]).describe("Sui-like transaction type");
246
248
  z7.union([
247
249
  zBitcoinLikeTransactionType,
248
250
  zCardanoLikeTransactionType,
@@ -253,6 +255,7 @@ z7.union([
253
255
  zRippleLikeTransactionType,
254
256
  zSolanaLikeTransactionType,
255
257
  zStellarLikeTransactionType,
258
+ zSuiLikeTransactionType,
256
259
  zTezosLikeTransactionType
257
260
  ]);
258
261
  z7.discriminatedUnion("type", [
@@ -280,7 +283,7 @@ var zCommonTransactionData = z7.object({
280
283
  currency: zCurrency.describe("Transaction currency"),
281
284
  // TODO: strict literal or enum?
282
285
  maxFee: zUnsignedIntString.nullable().describe("Transaction max fee"),
283
- recipient: z7.string().describe("Transaction recipient")
286
+ recipient: z7.string().nonempty().describe("Transaction recipient")
284
287
  });
285
288
  var zFeeStrategyCustom = z7.object({
286
289
  type: z7.enum(["SLOW", "NORMAL", "FAST", "CUSTOM"])
@@ -326,16 +329,24 @@ var zTezosLikeFeeStrategy = zFeeStrategyCustom.extend({
326
329
  gasLimit: zUnsignedIntString.describe("Gas limit"),
327
330
  storageLimit: zUnsignedIntString.nullable().describe("Storage limit")
328
331
  }).describe("Tezos-like fee strategy");
329
- var zTezosLikeDelegateData = zCommonTransactionData.extend({
330
- type: z7.literal(zTezosLikeTransactionType.enum.TEZOS_LIKE_DELEGATE),
331
- feeStrategy: zTezosLikeFeeStrategy
332
- }).describe("Tezos-like delegate data");
333
332
  var zTezosLikeSendData = zCommonTransactionData.extend({
334
333
  type: z7.literal(zTezosLikeTransactionType.enum.TEZOS_LIKE_SEND),
335
334
  feeStrategy: zTezosLikeFeeStrategy
336
335
  }).describe("Tezos-like send data");
337
- var zTezosLikeUndelegateData = zCommonTransactionData.extend({
336
+ var zTezosLikeDelegateData = z7.object({
337
+ type: z7.literal(zTezosLikeTransactionType.enum.TEZOS_LIKE_DELEGATE),
338
+ amount: zUnsignedIntString.optional().describe("Deprecated: DO NOT USE!"),
339
+ currency: zCurrency.describe("Transaction currency"),
340
+ maxFee: zUnsignedIntString.nullable().describe("Transaction max fee"),
341
+ recipient: z7.string().nonempty().describe("Transaction recipient"),
342
+ feeStrategy: zTezosLikeFeeStrategy
343
+ }).describe("Tezos-like delegate data");
344
+ var zTezosLikeUndelegateData = z7.object({
338
345
  type: z7.literal(zTezosLikeTransactionType.enum.TEZOS_LIKE_UNDELEGATE),
346
+ amount: zUnsignedIntString.optional().describe("Deprecated: DO NOT USE!"),
347
+ currency: zCurrency.describe("Transaction currency"),
348
+ maxFee: zUnsignedIntString.nullable().describe("Transaction max fee"),
349
+ recipient: z7.string().nonempty().optional().describe("Deprecated: DO NOT USE!"),
339
350
  feeStrategy: zTezosLikeFeeStrategy
340
351
  }).describe("Tezos-like undelegate data");
341
352
  var zPolkadotRewardDestination = z7.enum(["Staked", "Stash"]);
@@ -529,6 +540,14 @@ var zCardanoStakingWithdrawData = z7.object({
529
540
  // WITHDRAW doesn't have a recipient
530
541
  amount: zUnsignedIntString.describe("Amount to withdraw")
531
542
  }).describe("Cardano-like staking withdraw data");
543
+ var zSuiLikeSendData = zCommonTransactionData.extend({
544
+ type: z7.literal(zSuiLikeTransactionType.enum.SUI_LIKE_SEND),
545
+ feeStrategy: zFeeStrategy.describe("Sui-like fee strategy")
546
+ }).describe("Sui-like send data");
547
+ var zSuiLikeTransferTokenData = zCommonTransactionData.extend({
548
+ type: z7.literal(zSuiLikeTransactionType.enum.SUI_LIKE_TRANSFER_TOKEN),
549
+ feeStrategy: zFeeStrategy.describe("Sui-like fee strategy")
550
+ }).describe("Sui-like transfer token data");
532
551
  var zGenericTransactionData = z7.object({
533
552
  type: z7.literal(zGenericTransactionType.enum.GENERIC_TRANSACTION),
534
553
  currency: zCurrency.describe("Transaction currency"),
@@ -577,6 +596,9 @@ var zTransactionData = z7.discriminatedUnion("type", [
577
596
  zSolanaLikeFundTokenData,
578
597
  // Stellar
579
598
  zStellarLikeSendData,
599
+ // Sui
600
+ zSuiLikeSendData,
601
+ zSuiLikeTransferTokenData,
580
602
  // Tezos
581
603
  zTezosLikeDelegateData,
582
604
  zTezosLikeSendData,
@@ -590,6 +612,7 @@ var zSendOnlyTransactionData = z7.discriminatedUnion("type", [
590
612
  zRippleLikeSendData,
591
613
  zSolanaLikeSendData,
592
614
  zStellarLikeSendData,
615
+ zSuiLikeSendData,
593
616
  zTezosLikeSendData
594
617
  ]);
595
618
  var zCreateTransactionRequestData = z7.object({
@@ -740,6 +763,10 @@ var zStellarLikeAssetFields = z.object({
740
763
  type: z.literal(AccountType.STELLAR_LIKE).describe("Account type"),
741
764
  address: z.string().describe("Account address").nullable()
742
765
  }).describe("Stellar-like");
766
+ var zSuiLikeAssetFields = z.object({
767
+ type: z.literal(AccountType.SUI_LIKE).describe("Account type"),
768
+ address: z.string().describe("Account address").nullable()
769
+ }).describe("Sui-like");
743
770
  var zTezosLikeAssetFields = z.object({
744
771
  type: z.literal(AccountType.TEZOS_LIKE).describe("Account type"),
745
772
  address: z.string().describe("Account address").nullable()
@@ -755,7 +782,8 @@ var zAccountAssetStaticFields = z.discriminatedUnion("type", [
755
782
  zRippleLikeAssetFields,
756
783
  zSolanaLikeAssetFields,
757
784
  zStellarLikeAssetFields,
758
- zTezosLikeAssetFields
785
+ zTezosLikeAssetFields,
786
+ zSuiLikeAssetFields
759
787
  ]).describe("Account asset fields");
760
788
  var zReviewStepWithUsers = z.object({
761
789
  quorum: z.number().min(0).describe("Number of required approvals for the step"),
@@ -1144,6 +1172,9 @@ var zSolanaLikeLiveData = zCommonLiveData.merge(zSolanaLikeStakingFields).descri
1144
1172
  var zStellarLikeLiveData = zCommonLiveData.extend({
1145
1173
  type: z7.literal(AccountType.STELLAR_LIKE).describe("Account type")
1146
1174
  }).describe("Stellar-like");
1175
+ var zSuiLikeLiveData = zCommonLiveData.extend({
1176
+ type: z7.literal(AccountType.SUI_LIKE).describe("Account type")
1177
+ }).describe("Sui-like");
1147
1178
  var zTezosLikeLiveData = zCommonLiveData.merge(zTezosLikeStakingFields).describe("Tezos-like");
1148
1179
  z7.discriminatedUnion("type", [
1149
1180
  zBitcoinLikeLiveData,
@@ -1156,8 +1187,13 @@ z7.discriminatedUnion("type", [
1156
1187
  zRippleLikeLiveData,
1157
1188
  zSolanaLikeLiveData,
1158
1189
  zStellarLikeLiveData,
1190
+ zSuiLikeLiveData,
1159
1191
  zTezosLikeLiveData
1160
1192
  ]);
1193
+ z7.object({
1194
+ address: z7.string().describe("Address"),
1195
+ derivationPath: z7.string().nullable().describe("Derivation path")
1196
+ });
1161
1197
 
1162
1198
  // src/accounts/app-types.ts
1163
1199
  z7.discriminatedUnion(
@@ -1330,6 +1366,11 @@ var getAccountAssetStaticFields = (account) => {
1330
1366
  type: account.type,
1331
1367
  address: account.address
1332
1368
  };
1369
+ case AccountType.SUI_LIKE:
1370
+ return {
1371
+ type: account.type,
1372
+ address: account.address
1373
+ };
1333
1374
  case AccountType.RIPPLE_LIKE:
1334
1375
  return {
1335
1376
  type: account.type,
@@ -1382,6 +1423,28 @@ var serializeAccount = (account) => {
1382
1423
  };
1383
1424
  return zAccountResponse.parse(response);
1384
1425
  };
1426
+
1427
+ // src/compat/patch-request-expired-at.ts
1428
+ var patchRequestExpiredAt = (data) => ({
1429
+ ...data,
1430
+ expiredAt: data.expiresAt
1431
+ });
1432
+ var patchTezosRequestData = (data) => {
1433
+ if (data.type !== RequestType.CREATE_TRANSACTION) {
1434
+ return data;
1435
+ }
1436
+ const transaction = get(data, ["data", "transaction"]);
1437
+ if (!isRecord(transaction)) {
1438
+ return data;
1439
+ }
1440
+ if (transaction.type === "TEZOS_LIKE_DELEGATE") {
1441
+ transaction.amount = transaction.amount ?? "0";
1442
+ } else if (transaction.type === "TEZOS_LIKE_UNDELEGATE") {
1443
+ transaction.amount = transaction.amount ?? "0";
1444
+ transaction.recipient = transaction.recipient ?? "0";
1445
+ }
1446
+ return data;
1447
+ };
1385
1448
  var zSciConfigData = z7.object({
1386
1449
  dapps: z7.array(z7.string()).nullable().describe("Allowed DApps, null allows all"),
1387
1450
  customContractCallEnabled: z7.boolean().describe("Allow non-DApp SCI")
@@ -1680,6 +1743,7 @@ var zVaultRequestCommonMixin = z7.object({
1680
1743
  reviewSteps: zRequestReviewSteps.describe("Request review steps"),
1681
1744
  currentStepIndex: z7.number().int().min(0).describe("Index of the current approval step"),
1682
1745
  expiresAt: z7.coerce.date().describe("Request expiration date"),
1746
+ expiredAt: z7.coerce.date().optional().describe("Deprecated: use expiresAt"),
1683
1747
  targetId: z7.string().nullable().describe("Optional ID of the target object"),
1684
1748
  note: zNote.nullable().describe("Optional request note"),
1685
1749
  reviews: z7.array(zRequestReviewResponse).describe("Requests reviews"),
@@ -1873,8 +1937,12 @@ function serializeVaultRequest(request) {
1873
1937
  });
1874
1938
  break;
1875
1939
  }
1876
- return zVaultRequestResponse.parse(serialized);
1940
+ let patched = zVaultRequestResponse.parse(serialized);
1941
+ patched = patchRequestExpiredAt(patched);
1942
+ patched = patchTezosRequestData(patched);
1943
+ return patched;
1877
1944
  }
1945
+ var fakeUniqueName = (length) => randomUUID().replace(/-/g, "").slice(0, 20);
1878
1946
  var fakeHexString = (length, casing = "upper") => faker.string.hexadecimal({ prefix: "", casing, length });
1879
1947
  var fakePubKey = () => fakeHexString(130);
1880
1948
  var fakeIntegerId = () => faker.number.int({ min: 1, max: 2e9 });
@@ -2016,6 +2084,17 @@ var genAssetFieldsForType = (type) => {
2016
2084
  hsmXpub,
2017
2085
  hsmChainCode
2018
2086
  };
2087
+ case "SUI_LIKE":
2088
+ return {
2089
+ type,
2090
+ currency: faker.helpers.arrayElement(["sui"]),
2091
+ derivationPath: "44'/784'/0'",
2092
+ address: faker.string.alphanumeric({ length: 34, casing: "mixed" }),
2093
+ contractAddress: faker.string.alphanumeric({ length: 34, casing: "mixed" }),
2094
+ xpub: null,
2095
+ hsmXpub,
2096
+ hsmChainCode: null
2097
+ };
2019
2098
  case "GENERIC_LIKE":
2020
2099
  return {
2021
2100
  type,
@@ -2076,7 +2155,7 @@ var genAccount = (opts) => {
2076
2155
  const commonFields = {
2077
2156
  id: faker.string.uuid(),
2078
2157
  workspaceName: fakeWorkspaceName(),
2079
- name: faker.finance.accountName(),
2158
+ name: fakeUniqueName(),
2080
2159
  hsmId: fakeHsmObjectId(),
2081
2160
  status: ActivationStatus.ACTIVE,
2082
2161
  index: faker.number.int({ min: 0, max: 10 }),