wallaby-cash 2.2.11 → 2.2.13

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.esm.js CHANGED
@@ -4,6 +4,7 @@ import { AES, enc } from 'crypto-js';
4
4
  import { jwtDecode } from 'jwt-decode';
5
5
  import { omit } from 'lodash';
6
6
  import * as WebAuthn from '@simplewebauthn/browser';
7
+ import { atob, toUint8Array } from 'js-base64';
7
8
 
8
9
  /******************************************************************************
9
10
  Copyright (c) Microsoft Corporation.
@@ -769,7 +770,7 @@ const MASTER_ENCRYPTION_KEY = '9fa9d3f3c77c20d3a50a08e5299644be29f6e6206ef3479fe
769
770
  In particular, RS256 is necessary for compatibility with Microsoft Windows platform authenticators.
770
771
  ES256 is a widely supported algorithm and is compatible with most other platform authenticators and roaming authenticators.
771
772
  Therefore a Relying Party that uses an algorithm identifier list that omits either of those values will see registration failures when users attempt to use incompatible authenticators.
772
-
773
+
773
774
  https://chromium.googlesource.com/chromium/src/+/main/content/browser/webauth/pub_key_cred_params.md
774
775
  */
775
776
  [
@@ -777,7 +778,7 @@ const MASTER_ENCRYPTION_KEY = '9fa9d3f3c77c20d3a50a08e5299644be29f6e6206ef3479fe
777
778
  { type: 'public-key', alg: PublicKeyCredentialAlgorithm.ES256 },
778
779
  ];
779
780
  const isWeb = typeof window !== 'undefined' && typeof document !== 'undefined';
780
- const currentPackageVersion = "2.2.11";
781
+ const currentPackageVersion = "2.2.13" ;
781
782
 
782
783
  /**
783
784
  * Storage keys adapter for Storage interface across different platforms.
@@ -7004,12 +7005,16 @@ function objectToQueryParams(obj) {
7004
7005
 
7005
7006
  class Base {
7006
7007
  constructor(config) {
7007
- var _a;
7008
+ var _a, _b;
7008
7009
  const sanitizedConfig = sanitizeConfig(config);
7009
7010
  this.apiKey = sanitizedConfig.apiKey;
7010
7011
  this.baseUrl = sanitizedConfig.baseUrl;
7011
7012
  this.userId = sanitizedConfig.userId;
7012
7013
  this.options = sanitizedConfig.options;
7014
+ if ((_a = this.options) === null || _a === void 0 ? void 0 : _a.platform) {
7015
+ this.options.platform;
7016
+ this.options.platform === 'ios' || this.options.platform === 'android';
7017
+ }
7013
7018
  this.cipher = new Cipher();
7014
7019
  this.lockManager = new LockManagerService();
7015
7020
  this._initializeClientAuthToken(sanitizedConfig.clientAuthToken);
@@ -7054,7 +7059,7 @@ class Base {
7054
7059
  }
7055
7060
  };
7056
7061
  this.api = new Api(httpClient);
7057
- this.api.http.setSecurityData(Object.assign({ 'x-api-key': config.apiKey, 'x-client-jwt': config.clientAuthToken }, (_a = this.options) === null || _a === void 0 ? void 0 : _a.headers));
7062
+ this.api.http.setSecurityData(Object.assign({ 'x-api-key': config.apiKey, 'x-client-jwt': config.clientAuthToken }, (_b = this.options) === null || _b === void 0 ? void 0 : _b.headers));
7058
7063
  }
7059
7064
  set setClientAuthToken(token) {
7060
7065
  this._initializeClientAuthToken(token);
@@ -7605,6 +7610,50 @@ class Authenticator {
7605
7610
  }
7606
7611
  }
7607
7612
 
7613
+ /**
7614
+ * Shared base64 helpers. Platform-specific files (base64.ts, base64.native.ts)
7615
+ * import from here and add or re-export as needed.
7616
+ */
7617
+ function normalizeAndPadBase64(s) {
7618
+ const normalized = s.replace(/-/g, '+').replace(/_/g, '/');
7619
+ return normalized.padEnd(normalized.length + ((4 - (normalized.length % 4)) % 4), '=');
7620
+ }
7621
+ function decodeBase64String(s) {
7622
+ return toUint8Array(normalizeAndPadBase64(s));
7623
+ }
7624
+ function decodeBase64URL(base64url) {
7625
+ const padded = normalizeAndPadBase64(base64url);
7626
+ const binary = atob(padded);
7627
+ const bytes = new Uint8Array(binary.length);
7628
+ for (let i = 0; i < binary.length; i++) {
7629
+ bytes[i] = binary.charCodeAt(i);
7630
+ }
7631
+ return bytes;
7632
+ }
7633
+
7634
+ /**
7635
+ * Web: round-trip with uint8ArrayToBase64 (which does btoa(fromUint8Array(bytes, true))).
7636
+ * Single decode first; if the result looks like a base64 string, decode again to get original bytes.
7637
+ */
7638
+ function base64ToUint8Array(base64) {
7639
+ try {
7640
+ const first = toUint8Array(base64);
7641
+ const asStr = String.fromCharCode.apply(null, first);
7642
+ if (/^[A-Za-z0-9+/\-_=]*$/.test(asStr) && asStr.length >= 4) {
7643
+ try {
7644
+ return decodeBase64String(asStr);
7645
+ }
7646
+ catch (_a) {
7647
+ // fall through
7648
+ }
7649
+ }
7650
+ return first;
7651
+ }
7652
+ catch (_b) {
7653
+ return decodeBase64String(base64);
7654
+ }
7655
+ }
7656
+
7608
7657
  class PasskeyService {
7609
7658
  constructor(userId, storageService, request) {
7610
7659
  this.cipher = new Cipher();
@@ -7616,7 +7665,7 @@ class PasskeyService {
7616
7665
  preparePasskeyRequestOptions(options) {
7617
7666
  var _a, _b, _c, _d, _e, _f;
7618
7667
  const prfExtensionEvaluation = ((_b = (_a = options.extensions) === null || _a === void 0 ? void 0 : _a.prf.eval) === null || _b === void 0 ? void 0 : _b.base64)
7619
- ? WebAuthn.base64URLStringToBuffer(options.extensions.prf.eval.base64)
7668
+ ? decodeBase64URL(options.extensions.prf.eval.base64)
7620
7669
  : ((_d = (_c = options.extensions) === null || _c === void 0 ? void 0 : _c.prf.eval) === null || _d === void 0 ? void 0 : _d.first) instanceof ArrayBuffer
7621
7670
  ? new Uint8Array(options.extensions.prf.eval.first)
7622
7671
  : typeof ((_f = (_e = options.extensions) === null || _e === void 0 ? void 0 : _e.prf.eval) === null || _f === void 0 ? void 0 : _f.first) === 'object'
@@ -7636,7 +7685,7 @@ class PasskeyService {
7636
7685
  preparePasskeyCreationOptions(options) {
7637
7686
  var _a, _b, _c, _d, _e, _f;
7638
7687
  const prfExtensionEvaluation = ((_b = (_a = options.extensions) === null || _a === void 0 ? void 0 : _a.prf.eval) === null || _b === void 0 ? void 0 : _b.base64)
7639
- ? WebAuthn.base64URLStringToBuffer(options.extensions.prf.eval.base64)
7688
+ ? decodeBase64URL(options.extensions.prf.eval.base64)
7640
7689
  : ((_d = (_c = options.extensions) === null || _c === void 0 ? void 0 : _c.prf.eval) === null || _d === void 0 ? void 0 : _d.first) instanceof ArrayBuffer
7641
7690
  ? new Uint8Array(options.extensions.prf.eval.first)
7642
7691
  : typeof ((_f = (_e = options.extensions) === null || _e === void 0 ? void 0 : _e.prf.eval) === null || _f === void 0 ? void 0 : _f.first) === 'object'
@@ -8037,8 +8086,50 @@ class PasskeyService {
8037
8086
  errorCode: ErrorResponseCodes.sdk_passkey_prf_not_available,
8038
8087
  });
8039
8088
  }
8040
- const prfValue = new Uint8Array((_e = extensions.prf.results) === null || _e === void 0 ? void 0 : _e.first);
8041
- logger.debug('SDK::PasskeyService::handleCredentialsCreationFromPrfExtension::prfValue', !!prfValue);
8089
+ const prfResult = (_e = extensions.prf.results) === null || _e === void 0 ? void 0 : _e.first;
8090
+ let prfValue;
8091
+ if (typeof prfResult === 'string') {
8092
+ prfValue = base64ToUint8Array(prfResult);
8093
+ }
8094
+ else if (prfResult instanceof Uint8Array) {
8095
+ prfValue = prfResult;
8096
+ }
8097
+ else if (prfResult instanceof ArrayBuffer) {
8098
+ prfValue = new Uint8Array(prfResult);
8099
+ }
8100
+ else if (ArrayBuffer.isView(prfResult)) {
8101
+ prfValue = new Uint8Array(prfResult.buffer);
8102
+ }
8103
+ else if (Array.isArray(prfResult)) {
8104
+ prfValue = new Uint8Array(prfResult);
8105
+ }
8106
+ else if (prfResult && typeof prfResult === 'object') {
8107
+ const data = prfResult.data;
8108
+ if (Array.isArray(data)) {
8109
+ prfValue = new Uint8Array(data);
8110
+ }
8111
+ else {
8112
+ const values = Object.values(prfResult);
8113
+ if (values.length && values.every((value) => typeof value === 'number')) {
8114
+ prfValue = new Uint8Array(values);
8115
+ }
8116
+ else {
8117
+ throw new WallabyError({
8118
+ message: 'Unsupported PRF result type.',
8119
+ statusCode: 400,
8120
+ errorCode: ErrorResponseCodes.sdk_passkey_prf_not_available,
8121
+ });
8122
+ }
8123
+ }
8124
+ }
8125
+ else {
8126
+ throw new WallabyError({
8127
+ message: 'Unsupported PRF result type.',
8128
+ statusCode: 400,
8129
+ errorCode: ErrorResponseCodes.sdk_passkey_prf_not_available,
8130
+ });
8131
+ }
8132
+ logger.debug('SDK::PasskeyService::handleCredentialsCreationFromPrfExtension::prfValue', prfValue);
8042
8133
  const credentialsKeyPair = await this.cipher.getCredentialsKeyPair({
8043
8134
  prfValue,
8044
8135
  authType: AuthType.Passkey,
@@ -8381,7 +8472,6 @@ class AuthService extends Base {
8381
8472
  let deviceKeyPair;
8382
8473
  // This logic needs to change and depend on data from server.
8383
8474
  if (!passkeyCredential) {
8384
- console.debug('SDK::AuthService::handleSignInWithPasskey:: creating new key pair');
8385
8475
  deviceKeyPair = createIdentity();
8386
8476
  devicePublicKey = deviceKeyPair.publicKey;
8387
8477
  await this.localStorageService.save(LocalStorageItems.ClientAuthPublicKey, devicePublicKey);
@@ -10421,7 +10511,7 @@ class WalletDataService extends Base {
10421
10511
  * @param { string } address Wallet address
10422
10512
  * @param { string } symbol Token symbol
10423
10513
  * @param { BlockchainName } chainName the chain name enum. i.e. 'ETHEREUM', 'BITCOIN'
10424
- * @returns { TokenBalanceResponse } The wallet has been created successfully
10514
+ * @returns { TokenBalance } Balance of the token
10425
10515
  */
10426
10516
  async getTokenBalance({ address, symbol, tokenStandard, chainName }) {
10427
10517
  try {