wallaby-cash 2.0.4 → 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.cjs.js CHANGED
@@ -98,6 +98,14 @@ exports.TransportEnum = void 0;
98
98
  TransportEnum["Hybrid"] = "hybrid";
99
99
  })(exports.TransportEnum || (exports.TransportEnum = {}));
100
100
 
101
+ const isWallabyError = (obj) => {
102
+ return (!!obj &&
103
+ typeof obj === 'object' &&
104
+ 'statusCode' in obj &&
105
+ 'message' in obj &&
106
+ typeof obj.statusCode === 'number' &&
107
+ (obj.statusCode >= 400 || 'error' in obj));
108
+ };
101
109
  exports.UserAssetSource = void 0;
102
110
  (function (UserAssetSource) {
103
111
  UserAssetSource["Merchant"] = "merchant";
@@ -10936,9 +10944,9 @@ class Transactions extends Base {
10936
10944
  throw new Error('No valid seed option found on this device.');
10937
10945
  }
10938
10946
  if (!transferResponse ||
10939
- transferResponse.error ||
10947
+ isWallabyError(transferResponse) ||
10940
10948
  (typeof transferResponse === 'object' && Object.keys(transferResponse).length === 0)) {
10941
- throw new Error(transferResponse === null || transferResponse === void 0 ? void 0 : transferResponse.error);
10949
+ throw new Error(isWallabyError(transferResponse) ? transferResponse.error : 'Unknown error');
10942
10950
  }
10943
10951
  return transferResponse;
10944
10952
  }
@@ -10984,30 +10992,26 @@ class Transactions extends Base {
10984
10992
  logger.debug('Migration to V2 failed, continuing with original flow:', error);
10985
10993
  }
10986
10994
  }
10987
- const { deviceAuthPublicKey, signatureMessage, readyForTransportSeedPhrase } = await this.prepareTransactionAuth(authenticationOptions, walletId);
10995
+ const { deviceAuthPublicKey, signatureMessage, readyForTransportSeedPhrase, sharesEncryptedWithWallabyPubKey, hasShares } = await this.prepareTransactionAuth(authenticationOptions, walletId);
10988
10996
  const { message, signature } = signatureMessage;
10989
- // Create allowance only supports seed phrase for now, but we could extend it to support shares
10990
- if (!readyForTransportSeedPhrase) {
10991
- throw new Error('Create allowance requires a seed phrase. Key shares are not yet supported for this operation.');
10997
+ // Create allowance requires either a seed phrase or key shares
10998
+ if (!readyForTransportSeedPhrase && !hasShares) {
10999
+ throw new Error('No valid seed option found on this device.');
10992
11000
  }
11001
+ const payload = Object.assign({ message,
11002
+ walletId,
11003
+ authenticationOptions,
11004
+ signature, clientAuthPubKey: deviceAuthPublicKey, ownerAddress,
11005
+ spenderAddress,
11006
+ chainName,
11007
+ assetSymbol,
11008
+ amount,
11009
+ assetId, contractAddress: contractAddress !== null && contractAddress !== void 0 ? contractAddress : suiObjectId, reference,
11010
+ memo }, (hasShares ? { encryptedShares: sharesEncryptedWithWallabyPubKey } : { encryptedSeed: readyForTransportSeedPhrase }));
10993
11011
  const response = await this.request(TransactionsRoutes.createAllowance, {
10994
- payload: {
10995
- message,
10996
- signature,
10997
- clientAuthPubKey: deviceAuthPublicKey,
10998
- encryptedSeed: readyForTransportSeedPhrase,
10999
- ownerAddress,
11000
- spenderAddress,
11001
- chainName,
11002
- assetSymbol,
11003
- amount,
11004
- assetId,
11005
- contractAddress: contractAddress !== null && contractAddress !== void 0 ? contractAddress : suiObjectId,
11006
- reference,
11007
- memo,
11008
- },
11012
+ payload,
11009
11013
  });
11010
- if (response.error) {
11014
+ if (isWallabyError(response)) {
11011
11015
  throw new Error(response.error);
11012
11016
  }
11013
11017
  return response;
@@ -11175,6 +11179,7 @@ exports.createIdentity = createIdentity;
11175
11179
  exports.decryptWithPrivateKey = decryptWithPrivateKey;
11176
11180
  exports.encryptWithPublicKey = encryptWithPublicKey;
11177
11181
  exports.hash = hash;
11182
+ exports.isWallabyError = isWallabyError;
11178
11183
  exports.keccak256 = keccak256;
11179
11184
  exports.publicKeyByPrivateKey = publicKeyByPrivateKey;
11180
11185
  exports.recoverPublicKey = recoverPublicKey;