wallaby-cash 2.0.3 → 2.0.5

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/dist/index.js CHANGED
@@ -70,6 +70,14 @@ var TransportEnum;
70
70
  TransportEnum["Hybrid"] = "hybrid";
71
71
  })(TransportEnum || (TransportEnum = {}));
72
72
 
73
+ const isWallabyError = (obj) => {
74
+ return (!!obj &&
75
+ typeof obj === 'object' &&
76
+ 'statusCode' in obj &&
77
+ 'message' in obj &&
78
+ typeof obj.statusCode === 'number' &&
79
+ (obj.statusCode >= 400 || 'error' in obj));
80
+ };
73
81
  var UserAssetSource;
74
82
  (function (UserAssetSource) {
75
83
  UserAssetSource["Merchant"] = "merchant";
@@ -6990,7 +6998,7 @@ class Base {
6990
6998
  * @returns Promise of <T> where T is the type of the response.
6991
6999
  */
6992
7000
  async request(route, options) {
6993
- var _a, _b, _c, _d, _e, _f, _g, _h, _j;
7001
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
6994
7002
  try {
6995
7003
  let url;
6996
7004
  if (typeof route.fullPath !== 'string') {
@@ -7048,10 +7056,10 @@ class Base {
7048
7056
  if (((_e = error.response) === null || _e === void 0 ? void 0 : _e.data.errorCode) && error.response.data.errorCode === ErrorResponseCodes.user_already_exists) {
7049
7057
  return error.response.data;
7050
7058
  }
7051
- return Promise.reject(error.message);
7059
+ return Promise.reject((_f = error.response) === null || _f === void 0 ? void 0 : _f.data);
7052
7060
  }
7053
7061
  logger.error('SDK::Base::RequestMethod.Post::error', error);
7054
- return Promise.reject(error);
7062
+ return Promise.reject(error.message);
7055
7063
  }
7056
7064
  case RequestMethod.Put:
7057
7065
  try {
@@ -7061,8 +7069,8 @@ class Base {
7061
7069
  }
7062
7070
  catch (error) {
7063
7071
  if (error instanceof AxiosError) {
7064
- logger.error('SDK::Base::RequestMethod.Put::error', (_f = error.response) === null || _f === void 0 ? void 0 : _f.data);
7065
- return Promise.reject((_g = error.response) === null || _g === void 0 ? void 0 : _g.data);
7072
+ logger.error('SDK::Base::RequestMethod.Put::error', (_g = error.response) === null || _g === void 0 ? void 0 : _g.data);
7073
+ return Promise.reject((_h = error.response) === null || _h === void 0 ? void 0 : _h.data);
7066
7074
  }
7067
7075
  return Promise.reject(error === null || error === void 0 ? void 0 : error.message);
7068
7076
  }
@@ -7074,8 +7082,8 @@ class Base {
7074
7082
  }
7075
7083
  catch (error) {
7076
7084
  if (error instanceof AxiosError) {
7077
- logger.error('SDK::Base::RequestMethod.Put::AxiosError', (_h = error.response) === null || _h === void 0 ? void 0 : _h.data);
7078
- return Promise.reject((_j = error.response) === null || _j === void 0 ? void 0 : _j.data);
7085
+ logger.error('SDK::Base::RequestMethod.Put::AxiosError', (_j = error.response) === null || _j === void 0 ? void 0 : _j.data);
7086
+ return Promise.reject((_k = error.response) === null || _k === void 0 ? void 0 : _k.data);
7079
7087
  }
7080
7088
  return Promise.reject(error === null || error === void 0 ? void 0 : error.message);
7081
7089
  }
@@ -8396,14 +8404,6 @@ class AuthService extends Base {
8396
8404
  message: 'Password must be at least 8 characters long',
8397
8405
  };
8398
8406
  }
8399
- // Check if password contains at least 1 number
8400
- const hasNumber = /\d/.test(password);
8401
- if (!hasNumber) {
8402
- return {
8403
- valid: false,
8404
- message: 'Password must contain at least 1 number',
8405
- };
8406
- }
8407
8407
  // Check maximum length (128 characters) to avoid DDoS attacks
8408
8408
  if (password.length > 128) {
8409
8409
  return {
@@ -10916,9 +10916,9 @@ class Transactions extends Base {
10916
10916
  throw new Error('No valid seed option found on this device.');
10917
10917
  }
10918
10918
  if (!transferResponse ||
10919
- transferResponse.error ||
10919
+ isWallabyError(transferResponse) ||
10920
10920
  (typeof transferResponse === 'object' && Object.keys(transferResponse).length === 0)) {
10921
- throw new Error(transferResponse === null || transferResponse === void 0 ? void 0 : transferResponse.error);
10921
+ throw new Error(isWallabyError(transferResponse) ? transferResponse.error : 'Unknown error');
10922
10922
  }
10923
10923
  return transferResponse;
10924
10924
  }
@@ -10964,30 +10964,26 @@ class Transactions extends Base {
10964
10964
  logger.debug('Migration to V2 failed, continuing with original flow:', error);
10965
10965
  }
10966
10966
  }
10967
- const { deviceAuthPublicKey, signatureMessage, readyForTransportSeedPhrase } = await this.prepareTransactionAuth(authenticationOptions, walletId);
10967
+ const { deviceAuthPublicKey, signatureMessage, readyForTransportSeedPhrase, sharesEncryptedWithWallabyPubKey, hasShares } = await this.prepareTransactionAuth(authenticationOptions, walletId);
10968
10968
  const { message, signature } = signatureMessage;
10969
- // Create allowance only supports seed phrase for now, but we could extend it to support shares
10970
- if (!readyForTransportSeedPhrase) {
10971
- throw new Error('Create allowance requires a seed phrase. Key shares are not yet supported for this operation.');
10969
+ // Create allowance requires either a seed phrase or key shares
10970
+ if (!readyForTransportSeedPhrase && !hasShares) {
10971
+ throw new Error('No valid seed option found on this device.');
10972
10972
  }
10973
+ const payload = Object.assign({ message,
10974
+ walletId,
10975
+ authenticationOptions,
10976
+ signature, clientAuthPubKey: deviceAuthPublicKey, ownerAddress,
10977
+ spenderAddress,
10978
+ chainName,
10979
+ assetSymbol,
10980
+ amount,
10981
+ assetId, contractAddress: contractAddress !== null && contractAddress !== void 0 ? contractAddress : suiObjectId, reference,
10982
+ memo }, (hasShares ? { encryptedShares: sharesEncryptedWithWallabyPubKey } : { encryptedSeed: readyForTransportSeedPhrase }));
10973
10983
  const response = await this.request(TransactionsRoutes.createAllowance, {
10974
- payload: {
10975
- message,
10976
- signature,
10977
- clientAuthPubKey: deviceAuthPublicKey,
10978
- encryptedSeed: readyForTransportSeedPhrase,
10979
- ownerAddress,
10980
- spenderAddress,
10981
- chainName,
10982
- assetSymbol,
10983
- amount,
10984
- assetId,
10985
- contractAddress: contractAddress !== null && contractAddress !== void 0 ? contractAddress : suiObjectId,
10986
- reference,
10987
- memo,
10988
- },
10984
+ payload,
10989
10985
  });
10990
- if (response.error) {
10986
+ if (isWallabyError(response)) {
10991
10987
  throw new Error(response.error);
10992
10988
  }
10993
10989
  return response;
@@ -11120,5 +11116,5 @@ class Wallaby {
11120
11116
  }
11121
11117
  }
11122
11118
 
11123
- export { AddressType, AndroidVersionNotSupportedError, ApiKeyStatus, AssetConfigStatus, AssetType, AuthType, AuthenticatorGeneralError, AuthenticatorMissingDiscoverableCredentialSupportError, AuthenticatorMissingUserVerificationSupportError, AuthenticatorNoSupportedPubKeyCredParamsAlgError, AuthenticatorNotRegisteredError, AuthenticatorPreviouslyRegisteredError, AutoRegisterUserVerificationFailureError, BadConfiguration, BlockchainName, BlockchainSlip44, BlockchainStatus, CeremonyAbortedError, ErrorResponseCodes, IOSVersionNotSupportedError, InterruptedError, InvalidChallengeError, InvalidDomainError, InvalidRpIdError, InvalidStateError, InvalidUserIdError, InvalidUserIdLengthError, KeyTypeName, LegacyKeyNames, LocalStorageItems, MalformedPubKeyCredParamsError, NativeError, NoCredentialsError, NotAllowedError, OwnershipType, PasskeyChallengeType, PasskeyErrorCodes, PassthroughSeeCausePropertyError, PublicKeyCredentialAlgorithm, RequestFailedError, RequestMethod, ReturnWalletOption, SeedPhraseType, TimeoutError, TokenStandard, TransactionEntryType, TransportEnum, UnknownError, UserAssetSource, UserCancelledError, V1KeyNames, V2KeyNames, Wallaby, Api as WallabyApiClient, HttpClient as WallabyHttpClient, WalletAddressTypeName, WalletOwnershipType, createIdentity, decryptWithPrivateKey, encryptWithPublicKey, hash, keccak256, publicKeyByPrivateKey, recoverPublicKey, sign };
11119
+ export { AddressType, AndroidVersionNotSupportedError, ApiKeyStatus, AssetConfigStatus, AssetType, AuthType, AuthenticatorGeneralError, AuthenticatorMissingDiscoverableCredentialSupportError, AuthenticatorMissingUserVerificationSupportError, AuthenticatorNoSupportedPubKeyCredParamsAlgError, AuthenticatorNotRegisteredError, AuthenticatorPreviouslyRegisteredError, AutoRegisterUserVerificationFailureError, BadConfiguration, BlockchainName, BlockchainSlip44, BlockchainStatus, CeremonyAbortedError, ErrorResponseCodes, IOSVersionNotSupportedError, InterruptedError, InvalidChallengeError, InvalidDomainError, InvalidRpIdError, InvalidStateError, InvalidUserIdError, InvalidUserIdLengthError, KeyTypeName, LegacyKeyNames, LocalStorageItems, MalformedPubKeyCredParamsError, NativeError, NoCredentialsError, NotAllowedError, OwnershipType, PasskeyChallengeType, PasskeyErrorCodes, PassthroughSeeCausePropertyError, PublicKeyCredentialAlgorithm, RequestFailedError, RequestMethod, ReturnWalletOption, SeedPhraseType, TimeoutError, TokenStandard, TransactionEntryType, TransportEnum, UnknownError, UserAssetSource, UserCancelledError, V1KeyNames, V2KeyNames, Wallaby, Api as WallabyApiClient, HttpClient as WallabyHttpClient, WalletAddressTypeName, WalletOwnershipType, createIdentity, decryptWithPrivateKey, encryptWithPublicKey, hash, isWallabyError, keccak256, publicKeyByPrivateKey, recoverPublicKey, sign };
11124
11120
  //# sourceMappingURL=index.js.map