@ledgerhq/revault-api 1.34.0 → 1.36.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_SEND_TOKEN", "SUI_LIKE_RECEIVE_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", [
@@ -262,6 +265,18 @@ z7.discriminatedUnion("type", [
262
265
  gasLimit: zIntString,
263
266
  nonce: z7.string(),
264
267
  priorityFees: zIntString
268
+ }),
269
+ z7.object({
270
+ type: z7.literal("SUI_LIKE"),
271
+ fee: zIntString
272
+ }),
273
+ z7.object({
274
+ type: z7.literal("STELLAR_LIKE"),
275
+ fee: zIntString
276
+ }),
277
+ z7.object({
278
+ type: z7.literal("RIPPLE_LIKE"),
279
+ fee: zIntString
265
280
  })
266
281
  ]);
267
282
  var zMessageType = z7.enum(["EIP191", "EIP712"]);
@@ -280,7 +295,7 @@ var zCommonTransactionData = z7.object({
280
295
  currency: zCurrency.describe("Transaction currency"),
281
296
  // TODO: strict literal or enum?
282
297
  maxFee: zUnsignedIntString.nullable().describe("Transaction max fee"),
283
- recipient: z7.string().describe("Transaction recipient")
298
+ recipient: z7.string().nonempty().describe("Transaction recipient")
284
299
  });
285
300
  var zFeeStrategyCustom = z7.object({
286
301
  type: z7.enum(["SLOW", "NORMAL", "FAST", "CUSTOM"])
@@ -326,16 +341,24 @@ var zTezosLikeFeeStrategy = zFeeStrategyCustom.extend({
326
341
  gasLimit: zUnsignedIntString.describe("Gas limit"),
327
342
  storageLimit: zUnsignedIntString.nullable().describe("Storage limit")
328
343
  }).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
344
  var zTezosLikeSendData = zCommonTransactionData.extend({
334
345
  type: z7.literal(zTezosLikeTransactionType.enum.TEZOS_LIKE_SEND),
335
346
  feeStrategy: zTezosLikeFeeStrategy
336
347
  }).describe("Tezos-like send data");
337
- var zTezosLikeUndelegateData = zCommonTransactionData.extend({
348
+ var zTezosLikeDelegateData = z7.object({
349
+ type: z7.literal(zTezosLikeTransactionType.enum.TEZOS_LIKE_DELEGATE),
350
+ amount: zUnsignedIntString.optional().describe("Deprecated: DO NOT USE!"),
351
+ currency: zCurrency.describe("Transaction currency"),
352
+ maxFee: zUnsignedIntString.nullable().describe("Transaction max fee"),
353
+ recipient: z7.string().nonempty().describe("Transaction recipient"),
354
+ feeStrategy: zTezosLikeFeeStrategy
355
+ }).describe("Tezos-like delegate data");
356
+ var zTezosLikeUndelegateData = z7.object({
338
357
  type: z7.literal(zTezosLikeTransactionType.enum.TEZOS_LIKE_UNDELEGATE),
358
+ amount: zUnsignedIntString.optional().describe("Deprecated: DO NOT USE!"),
359
+ currency: zCurrency.describe("Transaction currency"),
360
+ maxFee: zUnsignedIntString.nullable().describe("Transaction max fee"),
361
+ recipient: z7.string().nonempty().optional().describe("Deprecated: DO NOT USE!"),
339
362
  feeStrategy: zTezosLikeFeeStrategy
340
363
  }).describe("Tezos-like undelegate data");
341
364
  var zPolkadotRewardDestination = z7.enum(["Staked", "Stash"]);
@@ -529,6 +552,14 @@ var zCardanoStakingWithdrawData = z7.object({
529
552
  // WITHDRAW doesn't have a recipient
530
553
  amount: zUnsignedIntString.describe("Amount to withdraw")
531
554
  }).describe("Cardano-like staking withdraw data");
555
+ var zSuiLikeSendData = zCommonTransactionData.extend({
556
+ type: z7.literal(zSuiLikeTransactionType.enum.SUI_LIKE_SEND),
557
+ feeStrategy: zFeeStrategy.describe("Sui-like fee strategy")
558
+ }).describe("Sui-like send data");
559
+ var zSuiLikeTransferTokenData = zCommonTransactionData.extend({
560
+ type: z7.literal(zSuiLikeTransactionType.enum.SUI_LIKE_SEND_TOKEN),
561
+ feeStrategy: zFeeStrategy.describe("Sui-like fee strategy")
562
+ }).describe("Sui-like transfer token data");
532
563
  var zGenericTransactionData = z7.object({
533
564
  type: z7.literal(zGenericTransactionType.enum.GENERIC_TRANSACTION),
534
565
  currency: zCurrency.describe("Transaction currency"),
@@ -577,6 +608,9 @@ var zTransactionData = z7.discriminatedUnion("type", [
577
608
  zSolanaLikeFundTokenData,
578
609
  // Stellar
579
610
  zStellarLikeSendData,
611
+ // Sui
612
+ zSuiLikeSendData,
613
+ zSuiLikeTransferTokenData,
580
614
  // Tezos
581
615
  zTezosLikeDelegateData,
582
616
  zTezosLikeSendData,
@@ -590,6 +624,7 @@ var zSendOnlyTransactionData = z7.discriminatedUnion("type", [
590
624
  zRippleLikeSendData,
591
625
  zSolanaLikeSendData,
592
626
  zStellarLikeSendData,
627
+ zSuiLikeSendData,
593
628
  zTezosLikeSendData
594
629
  ]);
595
630
  var zCreateTransactionRequestData = z7.object({
@@ -659,6 +694,9 @@ var zSolanaLikeCoinFields = z7.object({
659
694
  var zStellarLikeCoinFields = z7.object({
660
695
  type: zStellarLikeTransactionType
661
696
  });
697
+ var zSuiLikeCoinFields = z7.object({
698
+ type: zSuiLikeTransactionType
699
+ });
662
700
  var zTezosLikeCoinFields = z7.object({
663
701
  type: zTezosLikeTransactionType
664
702
  });
@@ -686,6 +724,7 @@ var zRippleLikeTransactionResponse = zCommonTransactionResponse.merge(zRippleLik
686
724
  var zSolanaLikeTransactionResponse = zCommonTransactionResponse.merge(zSolanaLikeCoinFields).describe("Solana-like transaction");
687
725
  var zStellarLikeTransactionResponse = zCommonTransactionResponse.merge(zStellarLikeCoinFields).describe("Stellar-like transaction");
688
726
  var zTezosLikeTransactionResponse = zCommonTransactionResponse.merge(zTezosLikeCoinFields).describe("Tezos-like transaction");
727
+ var zSuiLikeTransactionResponse = zCommonTransactionResponse.merge(zSuiLikeCoinFields).describe("Sui-like transaction");
689
728
  var zTransactionResponse = z7.discriminatedUnion("type", [
690
729
  zBitcoinLikeTransactionResponse,
691
730
  zCardanoLikeTransactionResponse,
@@ -696,6 +735,7 @@ var zTransactionResponse = z7.discriminatedUnion("type", [
696
735
  zRippleLikeTransactionResponse,
697
736
  zSolanaLikeTransactionResponse,
698
737
  zStellarLikeTransactionResponse,
738
+ zSuiLikeTransactionResponse,
699
739
  zTezosLikeTransactionResponse
700
740
  ]);
701
741
  z7.discriminatedUnion(
@@ -719,7 +759,9 @@ var zEthereumLikeAssetFields = z.object({
719
759
  var zEthereumTokenLikeAssetFields = z.object({
720
760
  type: z.enum([AccountType.ERC20_LIKE, AccountType.BEP20_LIKE, AccountType.TRC20_LIKE]).describe("Account type"),
721
761
  address: z.string().describe("Account address").nullable(),
722
- contractAddress: z.string().describe("Token contract address")
762
+ contractAddress: z.string().describe(
763
+ "Will be deprecated, Use contractAddress at root objet level instead; Token contract address"
764
+ ).optional()
723
765
  }).describe("Ethereum-like token");
724
766
  var zGenericLikeAssetFields = z.object({ type: z.literal(AccountType.GENERIC_LIKE).describe("Account type") }).describe("Generic-like");
725
767
  var zRawSigningAssetFields = z.object({ type: z.literal(AccountType.RAW_SIGNING).describe("Account type") }).describe("Raw signing account");
@@ -729,12 +771,14 @@ var zPolkadotLikeAssetFields = z.object({
729
771
  }).describe("Polkadot-like");
730
772
  var zRippleLikeAssetFields = z.object({
731
773
  type: z.literal(AccountType.RIPPLE_LIKE).describe("Account type"),
732
- xpub: z.string().describe("xpub (extended public key)")
774
+ address: z.string().describe("Account address").nullable()
733
775
  }).describe("Ripple-like");
734
776
  var zSolanaLikeAssetFields = z.object({
735
777
  type: z.literal(AccountType.SOLANA_LIKE).describe("Account type"),
736
778
  address: z.string().describe("Account address").nullable(),
737
- contractAddress: z.string().describe("Token contract address").nullable()
779
+ contractAddress: z.string().describe(
780
+ "Will be deprecated, Use contractAddress at root objet level instead; Token contract address"
781
+ ).nullable().optional()
738
782
  }).describe("Solana-like");
739
783
  var zStellarLikeAssetFields = z.object({
740
784
  type: z.literal(AccountType.STELLAR_LIKE).describe("Account type"),
@@ -1102,6 +1146,7 @@ var zAccountCommonFields = z7.object({
1102
1146
  legacyId: z7.number().describe("Legacy internal unique identifier (for retro-compatibility)"),
1103
1147
  name: z7.string().describe("Name"),
1104
1148
  currency: zCurrency,
1149
+ contractAddress: z7.string().describe("Token contract address for Token account").nullable(),
1105
1150
  index: z7.number().gte(0).describe("BIP44 account index"),
1106
1151
  derivationPath: z7.string().describe("Derivation path"),
1107
1152
  status: z7.nativeEnum(ActivationStatus).describe("Status"),
@@ -1167,6 +1212,10 @@ z7.discriminatedUnion("type", [
1167
1212
  zSuiLikeLiveData,
1168
1213
  zTezosLikeLiveData
1169
1214
  ]);
1215
+ z7.object({
1216
+ address: z7.string().describe("Address"),
1217
+ derivationPath: z7.string().nullable().describe("Derivation path")
1218
+ });
1170
1219
 
1171
1220
  // src/accounts/app-types.ts
1172
1221
  z7.discriminatedUnion(
@@ -1231,8 +1280,6 @@ var zEditPublicPolicyRequestData = z7.object({
1231
1280
  description: z7.string().nullable().describe("Description"),
1232
1281
  govRules: z7.array(zClassicGovRuleData).describe("Governance rules")
1233
1282
  });
1234
-
1235
- // src/accounts/request-data.ts
1236
1283
  var zAccountName = z7.string().min(1).max(40).describe("Account name");
1237
1284
  var zSignDigestsGovRuleData = z7.object({
1238
1285
  operationType: z7.literal("SIGN_DIGESTS"),
@@ -1347,7 +1394,7 @@ var getAccountAssetStaticFields = (account) => {
1347
1394
  case AccountType.RIPPLE_LIKE:
1348
1395
  return {
1349
1396
  type: account.type,
1350
- xpub: account.xpub
1397
+ address: account.address
1351
1398
  };
1352
1399
  case AccountType.POLKADOT_LIKE:
1353
1400
  return {
@@ -1396,6 +1443,28 @@ var serializeAccount = (account) => {
1396
1443
  };
1397
1444
  return zAccountResponse.parse(response);
1398
1445
  };
1446
+
1447
+ // src/compat/patch-request-expired-at.ts
1448
+ var patchRequestExpiredAt = (data) => ({
1449
+ ...data,
1450
+ expiredAt: data.expiresAt
1451
+ });
1452
+ var patchTezosRequestData = (data) => {
1453
+ if (data.type !== RequestType.CREATE_TRANSACTION) {
1454
+ return data;
1455
+ }
1456
+ const transaction = get(data, ["data", "transaction"]);
1457
+ if (!isRecord(transaction)) {
1458
+ return data;
1459
+ }
1460
+ if (transaction.type === "TEZOS_LIKE_DELEGATE") {
1461
+ transaction.amount = transaction.amount ?? "0";
1462
+ } else if (transaction.type === "TEZOS_LIKE_UNDELEGATE") {
1463
+ transaction.amount = transaction.amount ?? "0";
1464
+ transaction.recipient = transaction.recipient ?? "0";
1465
+ }
1466
+ return data;
1467
+ };
1399
1468
  var zSciConfigData = z7.object({
1400
1469
  dapps: z7.array(z7.string()).nullable().describe("Allowed DApps, null allows all"),
1401
1470
  customContractCallEnabled: z7.boolean().describe("Allow non-DApp SCI")
@@ -1442,6 +1511,7 @@ var zCreateApiUserAccessRequestData = z7.object({
1442
1511
  z7.object({
1443
1512
  authUserId: z7.string().describe("Authentication broker ID")
1444
1513
  }).describe("Managed data for API user");
1514
+ var zRevokeUserRequestData = z7.object({});
1445
1515
  var zGroupName = z7.string().min(1).max(19).describe("Group name");
1446
1516
  var zCreateGroupRequestData = z7.object({
1447
1517
  name: zGroupName,
@@ -1532,7 +1602,8 @@ var zVaultRequestMixinsByType = {
1532
1602
  }),
1533
1603
  [RequestType.REVOKE_GROUP]: z7.object({
1534
1604
  type: z7.literal(RequestType.REVOKE_GROUP),
1535
- data: z7.object({})
1605
+ targetId: z7.string(),
1606
+ data: zRevokeUserRequestData
1536
1607
  }),
1537
1608
  // Whitelists
1538
1609
  [RequestType.CREATE_WHITELIST]: z7.object({
@@ -1572,7 +1643,8 @@ var zVaultRequestMixinsByType = {
1572
1643
  }),
1573
1644
  [RequestType.REVOKE_USER]: z7.object({
1574
1645
  type: z7.literal(RequestType.REVOKE_USER),
1575
- data: z7.object({})
1646
+ targetId: z7.string(),
1647
+ data: zRevokeUserRequestData
1576
1648
  }),
1577
1649
  // Admin gov rules
1578
1650
  [RequestType.CREATE_WORKSPACE_RULE]: z7.object({
@@ -1694,6 +1766,7 @@ var zVaultRequestCommonMixin = z7.object({
1694
1766
  reviewSteps: zRequestReviewSteps.describe("Request review steps"),
1695
1767
  currentStepIndex: z7.number().int().min(0).describe("Index of the current approval step"),
1696
1768
  expiresAt: z7.coerce.date().describe("Request expiration date"),
1769
+ expiredAt: z7.coerce.date().optional().describe("Deprecated: use expiresAt"),
1697
1770
  targetId: z7.string().nullable().describe("Optional ID of the target object"),
1698
1771
  note: zNote.nullable().describe("Optional request note"),
1699
1772
  reviews: z7.array(zRequestReviewResponse).describe("Requests reviews"),
@@ -1703,7 +1776,7 @@ var zVaultRequestCommonMixin = z7.object({
1703
1776
  createdById: z7.string().describe("ID of the user who created the request"),
1704
1777
  // `inflight` is fetched from ONGOING RequestSaga
1705
1778
  inflight: z7.object({
1706
- lastError: z7.string().describe("Error message from the last failure"),
1779
+ lastError: z7.string().nullable().describe("Error message from the last failure"),
1707
1780
  numFailed: z7.number().int().describe("Number of failures so far"),
1708
1781
  retryAfter: z7.coerce.date().describe("Date after which next retry is scheduled")
1709
1782
  }).optional().describe("Extra information if the request is currently being processed")
@@ -1740,7 +1813,8 @@ var allowedRequestCreationInputByType = {
1740
1813
  [RequestType.FORCE_UNPLEDGE]: zVaultRequestMixinsByType[RequestType.FORCE_UNPLEDGE],
1741
1814
  [RequestType.CREATE_SETTLEMENT]: zVaultRequestMixinsByType[RequestType.CREATE_SETTLEMENT],
1742
1815
  [RequestType.TRADELINK_WITHDRAW]: zVaultRequestMixinsByType[RequestType.TRADELINK_WITHDRAW],
1743
- [RequestType.TRADELINK_ARBITRATE]: zVaultRequestMixinsByType[RequestType.TRADELINK_ARBITRATE]
1816
+ [RequestType.TRADELINK_ARBITRATE]: zVaultRequestMixinsByType[RequestType.TRADELINK_ARBITRATE],
1817
+ [RequestType.REVOKE_USER]: zVaultRequestMixinsByType[RequestType.REVOKE_USER]
1744
1818
  };
1745
1819
  var zRequestCreationInputCommonMixin = z7.object({
1746
1820
  note: zNote.optional().describe("Optional request note")
@@ -1887,8 +1961,12 @@ function serializeVaultRequest(request) {
1887
1961
  });
1888
1962
  break;
1889
1963
  }
1890
- return zVaultRequestResponse.parse(serialized);
1964
+ let patched = zVaultRequestResponse.parse(serialized);
1965
+ patched = patchRequestExpiredAt(patched);
1966
+ patched = patchTezosRequestData(patched);
1967
+ return patched;
1891
1968
  }
1969
+ var fakeUniqueName = (length) => randomUUID().replace(/-/g, "").slice(0, 20);
1892
1970
  var fakeHexString = (length, casing = "upper") => faker.string.hexadecimal({ prefix: "", casing, length });
1893
1971
  var fakePubKey = () => fakeHexString(130);
1894
1972
  var fakeIntegerId = () => faker.number.int({ min: 1, max: 2e9 });
@@ -2101,7 +2179,7 @@ var genAccount = (opts) => {
2101
2179
  const commonFields = {
2102
2180
  id: faker.string.uuid(),
2103
2181
  workspaceName: fakeWorkspaceName(),
2104
- name: faker.finance.accountName(),
2182
+ name: fakeUniqueName(),
2105
2183
  hsmId: fakeHsmObjectId(),
2106
2184
  status: ActivationStatus.ACTIVE,
2107
2185
  index: faker.number.int({ min: 0, max: 10 }),