wallaby-cash 2.0.1-alpha.35 → 2.0.1-alpha.37
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 +536 -304
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +508 -305
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +508 -305
- package/dist/index.js.map +1 -1
- package/dist/lib/auth/auth.model.d.ts +0 -1
- package/dist/lib/auth/auth.service.d.ts +1 -2
- package/dist/lib/auth/authenticator.d.ts +3 -1
- package/dist/lib/auth/passkey.service.d.ts +4 -3
- package/dist/lib/utils/constants.d.ts +3 -1
- package/dist/lib/utils/index.d.ts +5 -0
- package/dist/lib/wallet/wallet-data.service.d.ts +2 -2
- package/dist/lib/wallet/wallet.service.d.ts +15 -0
- package/dist/package.json +15 -5
- package/dist/types/common.d.ts +4 -3
- package/dist/types/index.d.ts +1 -0
- package/dist/types/passkey-error-codes.d.ts +3 -0
- package/dist/types/storage.d.ts +0 -4
- package/package.json +15 -5
- package/dist/helpers/base64.d.ts +0 -3
package/dist/index.cjs.js
CHANGED
|
@@ -5,10 +5,10 @@ Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toString
|
|
|
5
5
|
const uuid = require('uuid');
|
|
6
6
|
const axios = require('axios');
|
|
7
7
|
const log = require('loglevel');
|
|
8
|
+
const DeviceInfo = require('react-native-device-info');
|
|
8
9
|
const cryptoJs = require('crypto-js');
|
|
9
10
|
const jwtDecode = require('jwt-decode');
|
|
10
11
|
const lodash = require('lodash');
|
|
11
|
-
const jsBase64 = require('js-base64');
|
|
12
12
|
const WebAuthn = require('@simplewebauthn/browser');
|
|
13
13
|
|
|
14
14
|
const _interopDefaultCompat = e => e && typeof e === 'object' && 'default' in e ? e : { default: e };
|
|
@@ -33,6 +33,7 @@ return Object.freeze(n);
|
|
|
33
33
|
|
|
34
34
|
const axios__default = /*#__PURE__*/_interopDefaultCompat(axios);
|
|
35
35
|
const log__default = /*#__PURE__*/_interopDefaultCompat(log);
|
|
36
|
+
const DeviceInfo__default = /*#__PURE__*/_interopDefaultCompat(DeviceInfo);
|
|
36
37
|
const WebAuthn__namespace = /*#__PURE__*/_interopNamespaceCompat(WebAuthn);
|
|
37
38
|
|
|
38
39
|
/******************************************************************************
|
|
@@ -162,16 +163,17 @@ exports.BlockchainSlip44 = void 0;
|
|
|
162
163
|
exports.BlockchainName = void 0;
|
|
163
164
|
(function (BlockchainName) {
|
|
164
165
|
BlockchainName["Algorand"] = "ALGORAND";
|
|
166
|
+
BlockchainName["Aptos"] = "APTOS";
|
|
165
167
|
BlockchainName["Avalanche"] = "AVALANCHE";
|
|
166
168
|
BlockchainName["Bitcoin"] = "BITCOIN";
|
|
167
169
|
BlockchainName["Ethereum"] = "ETHEREUM";
|
|
170
|
+
BlockchainName["Injective"] = "INJECTIVE";
|
|
168
171
|
BlockchainName["Polygon"] = "POLYGON";
|
|
172
|
+
BlockchainName["Polymesh"] = "POLYMESH";
|
|
169
173
|
BlockchainName["Bsc"] = "BSC";
|
|
170
174
|
BlockchainName["Base"] = "BASE";
|
|
171
|
-
BlockchainName["Sui"] = "SUI";
|
|
172
|
-
BlockchainName["Injective"] = "INJECTIVE";
|
|
173
175
|
BlockchainName["Sei"] = "SEI";
|
|
174
|
-
BlockchainName["
|
|
176
|
+
BlockchainName["Sui"] = "SUI";
|
|
175
177
|
})(exports.BlockchainName || (exports.BlockchainName = {}));
|
|
176
178
|
exports.RequestMethod = void 0;
|
|
177
179
|
(function (RequestMethod) {
|
|
@@ -238,8 +240,6 @@ exports.LocalStorageItems = void 0;
|
|
|
238
240
|
LocalStorageItems["WallabyAuthPubKey"] = "wallaby-auth-pub-key";
|
|
239
241
|
LocalStorageItems["ClientAuthToken"] = "republic-jwt";
|
|
240
242
|
LocalStorageItems["PasskeyCredential"] = "pass-key-credential";
|
|
241
|
-
LocalStorageItems["PasskeyCredentialId"] = "pass-key-credential-id";
|
|
242
|
-
LocalStorageItems["PasskeyClientDataObject"] = "passkey-client-data";
|
|
243
243
|
LocalStorageItems["Blob"] = "blob";
|
|
244
244
|
})(exports.LocalStorageItems || (exports.LocalStorageItems = {}));
|
|
245
245
|
exports.LegacyKeyNames = void 0;
|
|
@@ -270,8 +270,6 @@ exports.V2KeyNames = void 0;
|
|
|
270
270
|
V2KeyNames["EncryptedDevicePrivateKey"] = "encrypted-private-key";
|
|
271
271
|
V2KeyNames["EncryptedStandardSeedPhrase"] = "encrypted-standard-seedPhrase";
|
|
272
272
|
V2KeyNames["PasskeyCredential"] = "pass-key-credential";
|
|
273
|
-
V2KeyNames["PasskeyCredentialId"] = "pass-key-credential-id";
|
|
274
|
-
V2KeyNames["PasskeyClientDataObject"] = "passkey-client-data";
|
|
275
273
|
V2KeyNames["PrimaryDeviceKeyShare"] = "primary-device-key-share";
|
|
276
274
|
V2KeyNames["WallabyAuthPubKey"] = "wallaby-auth-pub-key";
|
|
277
275
|
})(exports.V2KeyNames || (exports.V2KeyNames = {}));
|
|
@@ -324,7 +322,151 @@ exports.ErrorResponseCodes = void 0;
|
|
|
324
322
|
ErrorResponseCodes["merchant_not_found"] = "merchant_not_found";
|
|
325
323
|
})(exports.ErrorResponseCodes || (exports.ErrorResponseCodes = {}));
|
|
326
324
|
|
|
327
|
-
|
|
325
|
+
const UnknownError = {
|
|
326
|
+
error: 'UnknownError',
|
|
327
|
+
message: 'An unknown error occurred',
|
|
328
|
+
};
|
|
329
|
+
const IOSVersionNotSupportedError = {
|
|
330
|
+
error: 'IOSVersionNotSupportedError',
|
|
331
|
+
message: 'Passkeys are not supported on this device. iOS 15 and above is required to use Passkeys',
|
|
332
|
+
};
|
|
333
|
+
const AndroidVersionNotSupportedError = {
|
|
334
|
+
error: 'AndroidVersionNotSupportedError',
|
|
335
|
+
message: 'Passkeys are not supported on this device. Android 9 and above is required to use Passkeys',
|
|
336
|
+
};
|
|
337
|
+
const RequestFailedError = {
|
|
338
|
+
error: 'RequestFailed',
|
|
339
|
+
message: 'The request failed. No Credentials were returned.',
|
|
340
|
+
};
|
|
341
|
+
const UserCancelledError = {
|
|
342
|
+
error: 'UserCancelled',
|
|
343
|
+
message: 'The user cancelled the request.',
|
|
344
|
+
};
|
|
345
|
+
const InvalidChallengeError = {
|
|
346
|
+
error: 'InvalidChallenge',
|
|
347
|
+
message: 'The provided challenge was invalid',
|
|
348
|
+
};
|
|
349
|
+
const InvalidUserIdError = {
|
|
350
|
+
error: 'InvalidUserId',
|
|
351
|
+
message: 'The provided userId was invalid',
|
|
352
|
+
};
|
|
353
|
+
const BadConfiguration = {
|
|
354
|
+
error: 'BadConfiguration',
|
|
355
|
+
message: 'Your app is not properly configured. Refer to the docs for help.',
|
|
356
|
+
};
|
|
357
|
+
const NoCredentialsError = {
|
|
358
|
+
error: 'NoCredentials',
|
|
359
|
+
message: 'No viable credential is available for the user.',
|
|
360
|
+
};
|
|
361
|
+
const InterruptedError = {
|
|
362
|
+
error: 'Interrupted',
|
|
363
|
+
message: 'The operation was interrupted and may be retried.',
|
|
364
|
+
};
|
|
365
|
+
const TimeoutError = {
|
|
366
|
+
error: 'TimedOut',
|
|
367
|
+
message: 'The operation timed out.',
|
|
368
|
+
};
|
|
369
|
+
const CeremonyAbortedError = {
|
|
370
|
+
error: 'ERROR_CEREMONY_ABORTED',
|
|
371
|
+
message: 'User did not complete the request in time.',
|
|
372
|
+
};
|
|
373
|
+
const InvalidDomainError = {
|
|
374
|
+
error: 'ERROR_INVALID_DOMAIN',
|
|
375
|
+
message: 'Invalid domain.',
|
|
376
|
+
};
|
|
377
|
+
const InvalidRpIdError = {
|
|
378
|
+
error: 'ERROR_INVALID_RP_ID',
|
|
379
|
+
message: 'Invalid Relying Party ID.',
|
|
380
|
+
};
|
|
381
|
+
const InvalidUserIdLengthError = {
|
|
382
|
+
error: 'ERROR_INVALID_USER_ID_LENGTH',
|
|
383
|
+
message: 'Invalid user ID length.',
|
|
384
|
+
};
|
|
385
|
+
const MalformedPubKeyCredParamsError = {
|
|
386
|
+
error: 'ERROR_MALFORMED_PUBKEYCREDPARAMS',
|
|
387
|
+
message: 'Malformed public key credential parameters.',
|
|
388
|
+
};
|
|
389
|
+
const AuthenticatorGeneralError = {
|
|
390
|
+
error: 'ERROR_AUTHENTICATOR_GENERAL_ERROR',
|
|
391
|
+
message: 'Authenticator encountered a general error.',
|
|
392
|
+
};
|
|
393
|
+
const AuthenticatorMissingDiscoverableCredentialSupportError = {
|
|
394
|
+
error: 'ERROR_AUTHENTICATOR_MISSING_DISCOVERABLE_CREDENTIAL_SUPPORT',
|
|
395
|
+
message: 'Authenticator does not support discoverable credentials.',
|
|
396
|
+
};
|
|
397
|
+
const AuthenticatorMissingUserVerificationSupportError = {
|
|
398
|
+
error: 'ERROR_AUTHENTICATOR_MISSING_USER_VERIFICATION_SUPPORT',
|
|
399
|
+
message: 'Authenticator does not support user verification.',
|
|
400
|
+
};
|
|
401
|
+
const AuthenticatorPreviouslyRegisteredError = {
|
|
402
|
+
error: 'ERROR_AUTHENTICATOR_PREVIOUSLY_REGISTERED',
|
|
403
|
+
message: 'Authenticator was previously registered.',
|
|
404
|
+
};
|
|
405
|
+
const InvalidStateError = {
|
|
406
|
+
error: 'InvalidStateError',
|
|
407
|
+
message: 'The authenticator was previously registered',
|
|
408
|
+
};
|
|
409
|
+
const AuthenticatorNotRegisteredError = {
|
|
410
|
+
error: 'ERROR_AUTHENTICATOR_NOT_REGISTERED',
|
|
411
|
+
message: 'Authenticator is not registered.',
|
|
412
|
+
};
|
|
413
|
+
const AuthenticatorNoSupportedPubKeyCredParamsAlgError = {
|
|
414
|
+
error: 'ERROR_AUTHENTICATOR_NO_SUPPORTED_PUBKEYCREDPARAMS_ALG',
|
|
415
|
+
message: 'Authenticator does not support any of the provided public key credential parameters algorithms.',
|
|
416
|
+
};
|
|
417
|
+
const AutoRegisterUserVerificationFailureError = {
|
|
418
|
+
error: 'ERROR_AUTO_REGISTER_USER_VERIFICATION_FAILURE',
|
|
419
|
+
message: 'User verification failed during auto-registration.',
|
|
420
|
+
};
|
|
421
|
+
const PassthroughSeeCausePropertyError = {
|
|
422
|
+
error: 'ERROR_PASSTHROUGH_SEE_CAUSE_PROPERTY',
|
|
423
|
+
message: 'An error occurred. See the cause property for more details.',
|
|
424
|
+
};
|
|
425
|
+
const NotAllowedError = {
|
|
426
|
+
error: 'NotAllowedError',
|
|
427
|
+
message: 'CredentialContainer request is not allowed.',
|
|
428
|
+
};
|
|
429
|
+
const NativeError = (message = 'An unknown error occurred') => {
|
|
430
|
+
return {
|
|
431
|
+
error: 'Unknown',
|
|
432
|
+
message: message,
|
|
433
|
+
};
|
|
434
|
+
};
|
|
435
|
+
const PasskeyErrorCodes = [
|
|
436
|
+
UnknownError,
|
|
437
|
+
IOSVersionNotSupportedError,
|
|
438
|
+
AndroidVersionNotSupportedError,
|
|
439
|
+
RequestFailedError,
|
|
440
|
+
UserCancelledError,
|
|
441
|
+
InvalidChallengeError,
|
|
442
|
+
InvalidUserIdError,
|
|
443
|
+
BadConfiguration,
|
|
444
|
+
NoCredentialsError,
|
|
445
|
+
InterruptedError,
|
|
446
|
+
TimeoutError,
|
|
447
|
+
CeremonyAbortedError,
|
|
448
|
+
InvalidDomainError,
|
|
449
|
+
InvalidRpIdError,
|
|
450
|
+
InvalidUserIdLengthError,
|
|
451
|
+
MalformedPubKeyCredParamsError,
|
|
452
|
+
AuthenticatorGeneralError,
|
|
453
|
+
AuthenticatorMissingDiscoverableCredentialSupportError,
|
|
454
|
+
AuthenticatorMissingUserVerificationSupportError,
|
|
455
|
+
AuthenticatorPreviouslyRegisteredError,
|
|
456
|
+
AuthenticatorNoSupportedPubKeyCredParamsAlgError,
|
|
457
|
+
AutoRegisterUserVerificationFailureError,
|
|
458
|
+
PassthroughSeeCausePropertyError,
|
|
459
|
+
];
|
|
460
|
+
|
|
461
|
+
/* eslint-disable @typescript-eslint/no-unnecessary-condition */
|
|
462
|
+
const wallabyLogName = 'wsdk:enable_logging';
|
|
463
|
+
let shouldLog = false;
|
|
464
|
+
if (typeof window !== 'undefined' && window.localStorage) {
|
|
465
|
+
shouldLog = window.localStorage.getItem(wallabyLogName) === 'true';
|
|
466
|
+
}
|
|
467
|
+
if (shouldLog) {
|
|
468
|
+
log__default.default.setLevel('trace');
|
|
469
|
+
}
|
|
328
470
|
const logger = log__default.default;
|
|
329
471
|
|
|
330
472
|
const global$1 = (typeof global !== "undefined" ? global :
|
|
@@ -554,7 +696,6 @@ var browser$1 = {
|
|
|
554
696
|
};
|
|
555
697
|
|
|
556
698
|
var _a;
|
|
557
|
-
// import { versions } from 'node:process';
|
|
558
699
|
/**
|
|
559
700
|
* The default environment will be set to 'development' if environment is not set in config.
|
|
560
701
|
* For production builds, it is recommended to set NODE_ENV to 'production'.
|
|
@@ -587,6 +728,7 @@ const MASTER_ENCRYPTION_KEY = '9fa9d3f3c77c20d3a50a08e5299644be29f6e6206ef3479fe
|
|
|
587
728
|
{ type: 'public-key', alg: exports.PublicKeyCredentialAlgorithm.RS256 },
|
|
588
729
|
{ type: 'public-key', alg: exports.PublicKeyCredentialAlgorithm.ES256 },
|
|
589
730
|
];
|
|
731
|
+
DeviceInfo__default.default.getSystemName().toLowerCase();
|
|
590
732
|
|
|
591
733
|
const crypto = typeof globalThis === 'object' && 'crypto' in globalThis ? globalThis.crypto : undefined;
|
|
592
734
|
|
|
@@ -4815,13 +4957,7 @@ class StorageService {
|
|
|
4815
4957
|
exports.V2KeyNames.PrimaryDeviceKeyShare,
|
|
4816
4958
|
exports.V2KeyNames.BackupDeviceKeyShare,
|
|
4817
4959
|
];
|
|
4818
|
-
this._keysProtectedByMasterKey = [
|
|
4819
|
-
exports.V2KeyNames.AccessToken,
|
|
4820
|
-
exports.V2KeyNames.PasskeyClientDataObject,
|
|
4821
|
-
exports.V2KeyNames.PasskeyCredential,
|
|
4822
|
-
exports.V2KeyNames.PasskeyCredentialId,
|
|
4823
|
-
exports.V2KeyNames.ClientAuthToken,
|
|
4824
|
-
];
|
|
4960
|
+
this._keysProtectedByMasterKey = [exports.V2KeyNames.AccessToken, exports.V2KeyNames.PasskeyCredential, exports.V2KeyNames.ClientAuthToken];
|
|
4825
4961
|
this.userId = userId;
|
|
4826
4962
|
this.environment = environment !== null && environment !== void 0 ? environment : defaultEnvironment;
|
|
4827
4963
|
this.shortenedEnv = this.environment.slice(0, 1); // d for development
|
|
@@ -4863,7 +4999,14 @@ class StorageService {
|
|
|
4863
4999
|
return undefined;
|
|
4864
5000
|
}
|
|
4865
5001
|
if (this._keysProtectedByMasterKey.includes(key)) {
|
|
4866
|
-
|
|
5002
|
+
let unwrapped;
|
|
5003
|
+
// Temp fix to unblock prod issue. Need a more permanent solution.
|
|
5004
|
+
try {
|
|
5005
|
+
unwrapped = this.cipher.decryptWithMasterKey({ cipherText: item });
|
|
5006
|
+
}
|
|
5007
|
+
catch (_a) {
|
|
5008
|
+
unwrapped = item;
|
|
5009
|
+
}
|
|
4867
5010
|
if (!unwrapped) {
|
|
4868
5011
|
logger.error(`Failed to decrypt item with key ${storageKey}`);
|
|
4869
5012
|
return undefined;
|
|
@@ -5708,7 +5851,7 @@ const AuthRoutes = {
|
|
|
5708
5851
|
signIn: {
|
|
5709
5852
|
fullPath: '/auth/sign-in',
|
|
5710
5853
|
method: exports.RequestMethod.Post,
|
|
5711
|
-
requiresAccessToken:
|
|
5854
|
+
requiresAccessToken: false,
|
|
5712
5855
|
},
|
|
5713
5856
|
signUp: {
|
|
5714
5857
|
fullPath: '/auth/sign-up',
|
|
@@ -5803,140 +5946,6 @@ const TransactionsRoutes = {
|
|
|
5803
5946
|
},
|
|
5804
5947
|
};
|
|
5805
5948
|
|
|
5806
|
-
function base64ToUint8Array(base64) {
|
|
5807
|
-
const stringFromBase64 = jsBase64.fromBase64(base64);
|
|
5808
|
-
const binary = jsBase64.toUint8Array(stringFromBase64);
|
|
5809
|
-
return binary;
|
|
5810
|
-
}
|
|
5811
|
-
const decodeBase64URL = (base64url) => {
|
|
5812
|
-
const base64 = base64url.replace(/-/g, '+').replace(/_/g, '/');
|
|
5813
|
-
const padded = base64.padEnd(base64.length + ((4 - (base64.length % 4)) % 4), '=');
|
|
5814
|
-
const binary = jsBase64.atob(padded);
|
|
5815
|
-
const bytes = new Uint8Array(binary.length);
|
|
5816
|
-
for (let i = 0; i < binary.length; i++) {
|
|
5817
|
-
bytes[i] = binary.charCodeAt(i);
|
|
5818
|
-
}
|
|
5819
|
-
return bytes;
|
|
5820
|
-
};
|
|
5821
|
-
|
|
5822
|
-
const UnknownError = {
|
|
5823
|
-
error: 'UnknownError',
|
|
5824
|
-
message: 'An unknown error occurred',
|
|
5825
|
-
};
|
|
5826
|
-
const IOSVersionNotSupportedError = {
|
|
5827
|
-
error: 'IOSVersionNotSupportedError',
|
|
5828
|
-
message: 'Passkeys are not supported on this device. iOS 15 and above is required to use Passkeys',
|
|
5829
|
-
};
|
|
5830
|
-
const AndroidVersionNotSupportedError = {
|
|
5831
|
-
error: 'AndroidVersionNotSupportedError',
|
|
5832
|
-
message: 'Passkeys are not supported on this device. Android 9 and above is required to use Passkeys',
|
|
5833
|
-
};
|
|
5834
|
-
const RequestFailedError = {
|
|
5835
|
-
error: 'RequestFailed',
|
|
5836
|
-
message: 'The request failed. No Credentials were returned.',
|
|
5837
|
-
};
|
|
5838
|
-
const UserCancelledError = {
|
|
5839
|
-
error: 'UserCancelled',
|
|
5840
|
-
message: 'The user cancelled the request.',
|
|
5841
|
-
};
|
|
5842
|
-
const InvalidChallengeError = {
|
|
5843
|
-
error: 'InvalidChallenge',
|
|
5844
|
-
message: 'The provided challenge was invalid',
|
|
5845
|
-
};
|
|
5846
|
-
const InvalidUserIdError = {
|
|
5847
|
-
error: 'InvalidUserId',
|
|
5848
|
-
message: 'The provided userId was invalid',
|
|
5849
|
-
};
|
|
5850
|
-
const BadConfiguration = {
|
|
5851
|
-
error: 'BadConfiguration',
|
|
5852
|
-
message: 'Your app is not properly configured. Refer to the docs for help.',
|
|
5853
|
-
};
|
|
5854
|
-
const NoCredentialsError = {
|
|
5855
|
-
error: 'NoCredentials',
|
|
5856
|
-
message: 'No viable credential is available for the user.',
|
|
5857
|
-
};
|
|
5858
|
-
const InterruptedError = {
|
|
5859
|
-
error: 'Interrupted',
|
|
5860
|
-
message: 'The operation was interrupted and may be retried.',
|
|
5861
|
-
};
|
|
5862
|
-
const TimeoutError = {
|
|
5863
|
-
error: 'TimedOut',
|
|
5864
|
-
message: 'The operation timed out.',
|
|
5865
|
-
};
|
|
5866
|
-
const CeremonyAbortedError = {
|
|
5867
|
-
error: 'ERROR_CEREMONY_ABORTED',
|
|
5868
|
-
message: 'User did not complete the request in time.',
|
|
5869
|
-
};
|
|
5870
|
-
const InvalidDomainError = {
|
|
5871
|
-
error: 'ERROR_INVALID_DOMAIN',
|
|
5872
|
-
message: 'Invalid domain.',
|
|
5873
|
-
};
|
|
5874
|
-
const InvalidRpIdError = {
|
|
5875
|
-
error: 'ERROR_INVALID_RP_ID',
|
|
5876
|
-
message: 'Invalid Relying Party ID.',
|
|
5877
|
-
};
|
|
5878
|
-
const InvalidUserIdLengthError = {
|
|
5879
|
-
error: 'ERROR_INVALID_USER_ID_LENGTH',
|
|
5880
|
-
message: 'Invalid user ID length.',
|
|
5881
|
-
};
|
|
5882
|
-
const MalformedPubKeyCredParamsError = {
|
|
5883
|
-
error: 'ERROR_MALFORMED_PUBKEYCREDPARAMS',
|
|
5884
|
-
message: 'Malformed public key credential parameters.',
|
|
5885
|
-
};
|
|
5886
|
-
const AuthenticatorGeneralError = {
|
|
5887
|
-
error: 'ERROR_AUTHENTICATOR_GENERAL_ERROR',
|
|
5888
|
-
message: 'Authenticator encountered a general error.',
|
|
5889
|
-
};
|
|
5890
|
-
const AuthenticatorMissingDiscoverableCredentialSupportError = {
|
|
5891
|
-
error: 'ERROR_AUTHENTICATOR_MISSING_DISCOVERABLE_CREDENTIAL_SUPPORT',
|
|
5892
|
-
message: 'Authenticator does not support discoverable credentials.',
|
|
5893
|
-
};
|
|
5894
|
-
const AuthenticatorMissingUserVerificationSupportError = {
|
|
5895
|
-
error: 'ERROR_AUTHENTICATOR_MISSING_USER_VERIFICATION_SUPPORT',
|
|
5896
|
-
message: 'Authenticator does not support user verification.',
|
|
5897
|
-
};
|
|
5898
|
-
const AuthenticatorPreviouslyRegisteredError = {
|
|
5899
|
-
error: 'ERROR_AUTHENTICATOR_PREVIOUSLY_REGISTERED',
|
|
5900
|
-
message: 'Authenticator was previously registered.',
|
|
5901
|
-
};
|
|
5902
|
-
const AuthenticatorNoSupportedPubKeyCredParamsAlgError = {
|
|
5903
|
-
error: 'ERROR_AUTHENTICATOR_NO_SUPPORTED_PUBKEYCREDPARAMS_ALG',
|
|
5904
|
-
message: 'Authenticator does not support any of the provided public key credential parameters algorithms.',
|
|
5905
|
-
};
|
|
5906
|
-
const AutoRegisterUserVerificationFailureError = {
|
|
5907
|
-
error: 'ERROR_AUTO_REGISTER_USER_VERIFICATION_FAILURE',
|
|
5908
|
-
message: 'User verification failed during auto-registration.',
|
|
5909
|
-
};
|
|
5910
|
-
const PassthroughSeeCausePropertyError = {
|
|
5911
|
-
error: 'ERROR_PASSTHROUGH_SEE_CAUSE_PROPERTY',
|
|
5912
|
-
message: 'An error occurred. See the cause property for more details.',
|
|
5913
|
-
};
|
|
5914
|
-
const PasskeyErrorCodes = [
|
|
5915
|
-
UnknownError,
|
|
5916
|
-
IOSVersionNotSupportedError,
|
|
5917
|
-
AndroidVersionNotSupportedError,
|
|
5918
|
-
RequestFailedError,
|
|
5919
|
-
UserCancelledError,
|
|
5920
|
-
InvalidChallengeError,
|
|
5921
|
-
InvalidUserIdError,
|
|
5922
|
-
BadConfiguration,
|
|
5923
|
-
NoCredentialsError,
|
|
5924
|
-
InterruptedError,
|
|
5925
|
-
TimeoutError,
|
|
5926
|
-
CeremonyAbortedError,
|
|
5927
|
-
InvalidDomainError,
|
|
5928
|
-
InvalidRpIdError,
|
|
5929
|
-
InvalidUserIdLengthError,
|
|
5930
|
-
MalformedPubKeyCredParamsError,
|
|
5931
|
-
AuthenticatorGeneralError,
|
|
5932
|
-
AuthenticatorMissingDiscoverableCredentialSupportError,
|
|
5933
|
-
AuthenticatorMissingUserVerificationSupportError,
|
|
5934
|
-
AuthenticatorPreviouslyRegisteredError,
|
|
5935
|
-
AuthenticatorNoSupportedPubKeyCredParamsAlgError,
|
|
5936
|
-
AutoRegisterUserVerificationFailureError,
|
|
5937
|
-
PassthroughSeeCausePropertyError,
|
|
5938
|
-
];
|
|
5939
|
-
|
|
5940
5949
|
/* eslint-disable no-useless-catch */
|
|
5941
5950
|
/**
|
|
5942
5951
|
* Web Authenticator Implementation
|
|
@@ -5954,15 +5963,17 @@ class Authenticator {
|
|
|
5954
5963
|
if (typeof window === 'undefined' || !('navigator' in window) || !('credentials' in window.navigator)) {
|
|
5955
5964
|
throw new Error('WebAuthn is not supported in this browser.');
|
|
5956
5965
|
}
|
|
5957
|
-
|
|
5958
|
-
return response;
|
|
5966
|
+
return await WebAuthn__namespace.startRegistration({ optionsJSON });
|
|
5959
5967
|
}
|
|
5960
|
-
async authenticate({ optionsJSON, useBrowserAutofill = false, }) {
|
|
5968
|
+
async authenticate({ optionsJSON, useBrowserAutofill = false, skipUserVerification = false, }) {
|
|
5961
5969
|
try {
|
|
5962
5970
|
if (typeof window === 'undefined' || !('navigator' in window) || !('credentials' in window.navigator)) {
|
|
5963
5971
|
throw new Error('WebAuthn is not supported in this browser.');
|
|
5964
5972
|
}
|
|
5965
|
-
const response = await WebAuthn__namespace.startAuthentication({
|
|
5973
|
+
const response = await WebAuthn__namespace.startAuthentication({
|
|
5974
|
+
optionsJSON: Object.assign(Object.assign({}, optionsJSON), { userVerification: skipUserVerification ? 'discouraged' : optionsJSON.userVerification }),
|
|
5975
|
+
useBrowserAutofill,
|
|
5976
|
+
});
|
|
5966
5977
|
return response;
|
|
5967
5978
|
}
|
|
5968
5979
|
catch (error) {
|
|
@@ -5979,34 +5990,34 @@ class Authenticator {
|
|
|
5979
5990
|
logger.error('SDK::Authenticator::handlePasskeyError', error);
|
|
5980
5991
|
console.error('SDK::Authenticator::handlePasskeyError::code', error === null || error === void 0 ? void 0 : error.code);
|
|
5981
5992
|
if (error instanceof WebAuthn__namespace.WebAuthnError) {
|
|
5982
|
-
|
|
5983
|
-
return this.throwPasskeyError(error.code);
|
|
5993
|
+
logger.debug('SDK::Authenticator::handlePasskeyError - WebAuthnError', error);
|
|
5994
|
+
return this.throwPasskeyError({ errorCode: error.code });
|
|
5984
5995
|
}
|
|
5985
5996
|
else if (error instanceof Error) {
|
|
5986
|
-
|
|
5987
|
-
return this.throwPasskeyError(error.message
|
|
5997
|
+
logger.debug('SDK::Authenticator::handlePasskeyError - Error', error);
|
|
5998
|
+
return this.throwPasskeyError({ errorMessage: error.message });
|
|
5988
5999
|
}
|
|
5989
6000
|
else if (typeof error === 'object' && error.error && error.message) {
|
|
5990
|
-
|
|
5991
|
-
return this.throwPasskeyError(error.error);
|
|
6001
|
+
logger.debug('SDK::Authenticator::handlePasskeyError - Object', error);
|
|
6002
|
+
return this.throwPasskeyError({ errorCode: error.error, errorMessage: error.message });
|
|
5992
6003
|
}
|
|
5993
6004
|
else if (typeof error === 'string') {
|
|
5994
|
-
|
|
5995
|
-
return this.throwPasskeyError(error);
|
|
6005
|
+
logger.debug('SDK::Authenticator::handlePasskeyError - String', error);
|
|
6006
|
+
return this.throwPasskeyError({ errorMessage: error });
|
|
5996
6007
|
}
|
|
5997
6008
|
else {
|
|
5998
|
-
|
|
5999
|
-
return this.throwPasskeyError();
|
|
6009
|
+
logger.debug('SDK::Authenticator::handlePasskeyError - Unknown', error);
|
|
6010
|
+
return this.throwPasskeyError({});
|
|
6000
6011
|
}
|
|
6001
6012
|
}
|
|
6002
|
-
throwPasskeyError(errorCode) {
|
|
6003
|
-
var _a;
|
|
6013
|
+
throwPasskeyError({ errorCode, errorMessage }) {
|
|
6014
|
+
var _a, _b;
|
|
6004
6015
|
logger.error('SDK::Authenticator::throwPasskeyError', errorCode);
|
|
6005
6016
|
const errorToThrow = PasskeyErrorCodes.find((error) => {
|
|
6006
6017
|
return error.error === errorCode;
|
|
6007
6018
|
});
|
|
6008
6019
|
logger.error('SDK::Authenticator::error', errorToThrow);
|
|
6009
|
-
throw new Error((_a = errorToThrow === null || errorToThrow === void 0 ? void 0 : errorToThrow.message) !== null && _a !== void 0 ? _a : UnknownError.message);
|
|
6020
|
+
throw new Error((_b = (_a = errorToThrow === null || errorToThrow === void 0 ? void 0 : errorToThrow.message) !== null && _a !== void 0 ? _a : errorMessage) !== null && _b !== void 0 ? _b : UnknownError.message);
|
|
6010
6021
|
}
|
|
6011
6022
|
}
|
|
6012
6023
|
|
|
@@ -6021,22 +6032,18 @@ class PasskeyService {
|
|
|
6021
6032
|
preparePasskeyRequestOptions(options) {
|
|
6022
6033
|
var _a, _b, _c, _d, _e, _f;
|
|
6023
6034
|
const prfExtensionEvaluation = ((_b = (_a = options.extensions) === null || _a === void 0 ? void 0 : _a.prf.eval) === null || _b === void 0 ? void 0 : _b.base64)
|
|
6024
|
-
?
|
|
6035
|
+
? WebAuthn__namespace.base64URLStringToBuffer(options.extensions.prf.eval.base64)
|
|
6025
6036
|
: ((_d = (_c = options.extensions) === null || _c === void 0 ? void 0 : _c.prf.eval) === null || _d === void 0 ? void 0 : _d.first) instanceof ArrayBuffer
|
|
6026
6037
|
? new Uint8Array(options.extensions.prf.eval.first)
|
|
6027
6038
|
: typeof ((_f = (_e = options.extensions) === null || _e === void 0 ? void 0 : _e.prf.eval) === null || _f === void 0 ? void 0 : _f.first) === 'object'
|
|
6028
6039
|
? new Uint8Array(Object.values(options.extensions.prf.eval.first))
|
|
6029
6040
|
: undefined;
|
|
6030
|
-
|
|
6031
|
-
throw new Error('Passkey extension cannot be used at this time.');
|
|
6032
|
-
}
|
|
6033
|
-
const parsedOptions = Object.assign(Object.assign({}, options), { extensions: {
|
|
6034
|
-
prf: {
|
|
6041
|
+
const parsedOptions = Object.assign(Object.assign({}, options), { extensions: Object.assign(Object.assign({}, options.extensions), { prf: {
|
|
6035
6042
|
eval: {
|
|
6036
6043
|
first: prfExtensionEvaluation,
|
|
6037
6044
|
},
|
|
6038
|
-
}
|
|
6039
|
-
|
|
6045
|
+
} }) });
|
|
6046
|
+
console.log('SDK::PasskeyService::preparePasskeyRequestOptions::parsedOptions', parsedOptions);
|
|
6040
6047
|
// While the authenticator still works with the prf and would return the response (if any),
|
|
6041
6048
|
// the library `@simplewebauthn/browser` does not support the prf extension in its type intentionally.
|
|
6042
6049
|
// > "Using the prf extension does not fall under the simple use of webauthn."
|
|
@@ -6045,7 +6052,7 @@ class PasskeyService {
|
|
|
6045
6052
|
preparePasskeyCreationOptions(options) {
|
|
6046
6053
|
var _a, _b, _c, _d, _e, _f;
|
|
6047
6054
|
const prfExtensionEvaluation = ((_b = (_a = options.extensions) === null || _a === void 0 ? void 0 : _a.prf.eval) === null || _b === void 0 ? void 0 : _b.base64)
|
|
6048
|
-
?
|
|
6055
|
+
? WebAuthn__namespace.base64URLStringToBuffer(options.extensions.prf.eval.base64)
|
|
6049
6056
|
: ((_d = (_c = options.extensions) === null || _c === void 0 ? void 0 : _c.prf.eval) === null || _d === void 0 ? void 0 : _d.first) instanceof ArrayBuffer
|
|
6050
6057
|
? new Uint8Array(options.extensions.prf.eval.first)
|
|
6051
6058
|
: typeof ((_f = (_e = options.extensions) === null || _e === void 0 ? void 0 : _e.prf.eval) === null || _f === void 0 ? void 0 : _f.first) === 'object'
|
|
@@ -6056,6 +6063,7 @@ class PasskeyService {
|
|
|
6056
6063
|
first: prfExtensionEvaluation,
|
|
6057
6064
|
},
|
|
6058
6065
|
} }) });
|
|
6066
|
+
console.log('SDK::PasskeyService::preparePasskeyRequestOptions::parsedOptions', parsedOptions);
|
|
6059
6067
|
return parsedOptions;
|
|
6060
6068
|
}
|
|
6061
6069
|
/**
|
|
@@ -6064,73 +6072,88 @@ class PasskeyService {
|
|
|
6064
6072
|
* @param { SignatureMessageResponse } challengeResponse
|
|
6065
6073
|
* @returns { AuthResponse } The authentication response containing the access token and user information.
|
|
6066
6074
|
*/
|
|
6067
|
-
async addNewPasskey({ deviceKeyPair,
|
|
6075
|
+
async addNewPasskey({ deviceKeyPair, getSignature, }) {
|
|
6068
6076
|
try {
|
|
6077
|
+
// const isPrfEnabled = await this.isDevicePrfCompatible();
|
|
6078
|
+
// if (!isPrfEnabled)
|
|
6079
|
+
// throw new Error('Device is not compatible with this feature. Try using a different authentication method.');
|
|
6069
6080
|
let passkeyCredential;
|
|
6070
|
-
|
|
6071
|
-
|
|
6072
|
-
|
|
6073
|
-
|
|
6074
|
-
|
|
6075
|
-
|
|
6076
|
-
|
|
6077
|
-
|
|
6078
|
-
|
|
6079
|
-
|
|
6080
|
-
|
|
6081
|
-
|
|
6082
|
-
|
|
6083
|
-
|
|
6084
|
-
|
|
6085
|
-
|
|
6086
|
-
|
|
6081
|
+
let signInResponse;
|
|
6082
|
+
try {
|
|
6083
|
+
const registrationChallengeResponse = await getSignature(deviceKeyPair, exports.PasskeyChallengeType.REGISTRATION);
|
|
6084
|
+
if (!registrationChallengeResponse.registrationOptions)
|
|
6085
|
+
throw new Error('Passkey challenge could not be retrieved, please try again later.');
|
|
6086
|
+
const parsedOptions = this.preparePasskeyCreationOptions(registrationChallengeResponse.registrationOptions);
|
|
6087
|
+
passkeyCredential = await this.authenticator.register({
|
|
6088
|
+
optionsJSON: parsedOptions,
|
|
6089
|
+
});
|
|
6090
|
+
// before we sign the user in, we need to make sure the prf extension is enabled and we have a value.
|
|
6091
|
+
const credentialsKeyPair = await this.handleCredentialsCreationFromPrfExtension(passkeyCredential);
|
|
6092
|
+
signInResponse = await this.request(AuthRoutes.signIn, {
|
|
6093
|
+
payload: {
|
|
6094
|
+
externalUserId: this.userId,
|
|
6095
|
+
message: registrationChallengeResponse.message,
|
|
6096
|
+
clientAuthPubKey: deviceKeyPair.publicKey,
|
|
6097
|
+
signature: registrationChallengeResponse.signature,
|
|
6098
|
+
passkeyRegistrationResponse: passkeyCredential,
|
|
6099
|
+
},
|
|
6100
|
+
});
|
|
6101
|
+
const encryptedNewDevicePrivateKey = await this.cipher.encrypt({
|
|
6102
|
+
data: deviceKeyPair.privateKey,
|
|
6103
|
+
encryptionKey: credentialsKeyPair.publicKey,
|
|
6104
|
+
});
|
|
6105
|
+
await this.handleStoringData({
|
|
6106
|
+
authenticationResponse: signInResponse,
|
|
6107
|
+
deviceKeyPair: {
|
|
6108
|
+
publicKey: deviceKeyPair.publicKey,
|
|
6109
|
+
encryptedDevicePrivateKey: encryptedNewDevicePrivateKey,
|
|
6110
|
+
},
|
|
6111
|
+
passkeyCredential,
|
|
6112
|
+
});
|
|
6113
|
+
return Object.assign(Object.assign({}, signInResponse), { prfValue: credentialsKeyPair.prfValue });
|
|
6087
6114
|
}
|
|
6088
|
-
|
|
6089
|
-
|
|
6090
|
-
|
|
6115
|
+
catch (error) {
|
|
6116
|
+
logger.error('SDK::PasskeyService::addNewPasskey::error', error);
|
|
6117
|
+
if (error && error.code === AuthenticatorPreviouslyRegisteredError.error) {
|
|
6118
|
+
const authenticationChallengeResponse = await getSignature(deviceKeyPair, exports.PasskeyChallengeType.AUTHENTICATION);
|
|
6119
|
+
if (!authenticationChallengeResponse.authenticationOptions)
|
|
6120
|
+
throw new Error('Passkey challenge could not be retrieved, please try again later.');
|
|
6121
|
+
const parsedOptions = this.preparePasskeyRequestOptions(authenticationChallengeResponse.authenticationOptions);
|
|
6091
6122
|
passkeyCredential = await this.authenticator.authenticate({
|
|
6092
6123
|
optionsJSON: parsedOptions,
|
|
6093
6124
|
});
|
|
6125
|
+
signInResponse = await this.request(AuthRoutes.signIn, {
|
|
6126
|
+
payload: {
|
|
6127
|
+
externalUserId: this.userId,
|
|
6128
|
+
message: authenticationChallengeResponse.message,
|
|
6129
|
+
clientAuthPubKey: deviceKeyPair.publicKey,
|
|
6130
|
+
signature: authenticationChallengeResponse.signature,
|
|
6131
|
+
passkeyAuthenticationResponse: passkeyCredential,
|
|
6132
|
+
},
|
|
6133
|
+
});
|
|
6134
|
+
const credentialsKeyPair = await this.handleCredentialsCreationFromPrfExtension(passkeyCredential);
|
|
6135
|
+
const encryptedNewDevicePrivateKey = await this.cipher.encrypt({
|
|
6136
|
+
data: deviceKeyPair.privateKey,
|
|
6137
|
+
encryptionKey: credentialsKeyPair.publicKey,
|
|
6138
|
+
});
|
|
6139
|
+
await this.handleStoringData({
|
|
6140
|
+
authenticationResponse: signInResponse,
|
|
6141
|
+
deviceKeyPair: {
|
|
6142
|
+
publicKey: deviceKeyPair.publicKey,
|
|
6143
|
+
encryptedDevicePrivateKey: encryptedNewDevicePrivateKey,
|
|
6144
|
+
},
|
|
6145
|
+
passkeyCredential,
|
|
6146
|
+
});
|
|
6147
|
+
return Object.assign(Object.assign({}, signInResponse), { prfValue: credentialsKeyPair.prfValue });
|
|
6094
6148
|
}
|
|
6095
|
-
|
|
6096
|
-
if (error && error.code === 'ERROR_AUTHENTICATOR_NOT_REGISTERED') {
|
|
6097
|
-
logger.info('Authenticator is not registered');
|
|
6098
|
-
}
|
|
6099
|
-
}
|
|
6100
|
-
}
|
|
6101
|
-
else {
|
|
6102
|
-
throw new Error('Passkey challenge could not be retrieved, please try again later.');
|
|
6103
|
-
}
|
|
6104
|
-
if (!passkeyCredential)
|
|
6105
|
-
throw new Error('Passkey creation failed. Please try again.');
|
|
6106
|
-
const credentialsKeyPair = await this.handleCredentialsCreationFromPrfExtension(passkeyCredential);
|
|
6107
|
-
const signInResponse = await this.request(AuthRoutes.signIn, {
|
|
6108
|
-
payload: {
|
|
6109
|
-
externalUserId: this.userId,
|
|
6110
|
-
message: challengeResponse.message,
|
|
6111
|
-
clientAuthPubKey: deviceKeyPair.publicKey,
|
|
6112
|
-
signature: challengeResponse.signature,
|
|
6113
|
-
passkeyAuthenticationResponse: passkeyCredential,
|
|
6114
|
-
},
|
|
6115
|
-
});
|
|
6116
|
-
if (signInResponse.error) {
|
|
6117
|
-
throw new Error('Passkey authentication failed. Please try again.');
|
|
6149
|
+
throw error;
|
|
6118
6150
|
}
|
|
6119
|
-
const encryptedNewDevicePrivateKey = await this.cipher.encrypt({
|
|
6120
|
-
data: deviceKeyPair.privateKey,
|
|
6121
|
-
encryptionKey: credentialsKeyPair.publicKey,
|
|
6122
|
-
});
|
|
6123
|
-
await this.handleStoringData({
|
|
6124
|
-
authenticationResponse: signInResponse,
|
|
6125
|
-
deviceKeyPair: {
|
|
6126
|
-
publicKey: deviceKeyPair.publicKey,
|
|
6127
|
-
encryptedDevicePrivateKey: encryptedNewDevicePrivateKey,
|
|
6128
|
-
},
|
|
6129
|
-
passkeyCredential,
|
|
6130
|
-
});
|
|
6131
|
-
return Object.assign(Object.assign({}, signInResponse), { prfValue: credentialsKeyPair.prfValue });
|
|
6132
6151
|
}
|
|
6133
6152
|
catch (error) {
|
|
6153
|
+
// If it's an API error (has statusCode), preserve the original error message
|
|
6154
|
+
if (error && typeof error === 'object' && 'statusCode' in error && 'message' in error) {
|
|
6155
|
+
throw new Error(error.message);
|
|
6156
|
+
}
|
|
6134
6157
|
throw this.authenticator.handlePasskeyError(error);
|
|
6135
6158
|
}
|
|
6136
6159
|
}
|
|
@@ -6142,7 +6165,10 @@ class PasskeyService {
|
|
|
6142
6165
|
* @returns { AuthResponse } The authentication response containing the access token and user information.
|
|
6143
6166
|
*/
|
|
6144
6167
|
async authenticate({ deviceKeyPair, challengeResponse, }) {
|
|
6168
|
+
// const isPrfEnabled = await this.isDevicePrfCompatible();
|
|
6145
6169
|
var _a, _b;
|
|
6170
|
+
// if (!isPrfEnabled)
|
|
6171
|
+
// throw new Error('Device is not compatible with this feature. Try using a different authentication method.');
|
|
6146
6172
|
try {
|
|
6147
6173
|
if (!challengeResponse.authenticationOptions)
|
|
6148
6174
|
throw new Error('Passkey challenge could not be retrieved, please try again later.');
|
|
@@ -6156,19 +6182,20 @@ class PasskeyService {
|
|
|
6156
6182
|
optionsJSON: updatedOptions,
|
|
6157
6183
|
});
|
|
6158
6184
|
const credentialsKeyPair = await this.handleCredentialsCreationFromPrfExtension(passkeyCredential);
|
|
6159
|
-
|
|
6160
|
-
|
|
6161
|
-
|
|
6162
|
-
|
|
6163
|
-
|
|
6164
|
-
|
|
6165
|
-
|
|
6166
|
-
|
|
6185
|
+
// this isn't always present, when authenticating sometimes we need the PRF value first to decrypt the device private key.
|
|
6186
|
+
// before we're able to get a signature.
|
|
6187
|
+
const deviceSignature = challengeResponse.signature
|
|
6188
|
+
? challengeResponse.signature
|
|
6189
|
+
: await this.getDeviceSignature({
|
|
6190
|
+
message: challengeResponse.message,
|
|
6191
|
+
credentialsKeyPair,
|
|
6192
|
+
deviceKeyPair,
|
|
6193
|
+
});
|
|
6167
6194
|
const signInResponse = await this.request(AuthRoutes.signIn, {
|
|
6168
6195
|
payload: {
|
|
6169
6196
|
externalUserId: this.userId,
|
|
6170
|
-
message,
|
|
6171
|
-
signature,
|
|
6197
|
+
message: challengeResponse.message,
|
|
6198
|
+
signature: deviceSignature,
|
|
6172
6199
|
clientAuthPubKey: deviceKeyPair.publicKey,
|
|
6173
6200
|
passkeyAuthenticationResponse: passkeyCredential,
|
|
6174
6201
|
},
|
|
@@ -6176,17 +6203,58 @@ class PasskeyService {
|
|
|
6176
6203
|
if (signInResponse.error) {
|
|
6177
6204
|
throw new Error('Passkey authentication failed. Please try again.');
|
|
6178
6205
|
}
|
|
6206
|
+
const devicePrivateKeyForStorage = deviceKeyPair.decryptedPrivateKey
|
|
6207
|
+
? deviceKeyPair.decryptedPrivateKey
|
|
6208
|
+
: deviceKeyPair.encryptedDevicePrivateKey
|
|
6209
|
+
? await this.cipher.decrypt({
|
|
6210
|
+
cipherText: deviceKeyPair.encryptedDevicePrivateKey,
|
|
6211
|
+
decryptionKey: credentialsKeyPair.privateKey,
|
|
6212
|
+
})
|
|
6213
|
+
: undefined;
|
|
6214
|
+
if (!devicePrivateKeyForStorage)
|
|
6215
|
+
throw new Error('Device private key is not available for storage.');
|
|
6216
|
+
const encryptedPrivKey = await this.cipher.encrypt({
|
|
6217
|
+
data: devicePrivateKeyForStorage,
|
|
6218
|
+
encryptionKey: credentialsKeyPair.publicKey,
|
|
6219
|
+
});
|
|
6179
6220
|
await this.handleStoringData({
|
|
6180
6221
|
authenticationResponse: signInResponse,
|
|
6181
|
-
deviceKeyPair
|
|
6222
|
+
deviceKeyPair: {
|
|
6223
|
+
publicKey: deviceKeyPair.publicKey,
|
|
6224
|
+
encryptedDevicePrivateKey: encryptedPrivKey,
|
|
6225
|
+
},
|
|
6182
6226
|
passkeyCredential,
|
|
6183
6227
|
});
|
|
6184
6228
|
return Object.freeze(Object.assign(Object.assign({}, signInResponse), { prfValue: credentialsKeyPair.prfValue }));
|
|
6185
6229
|
}
|
|
6186
6230
|
catch (error) {
|
|
6231
|
+
// If it's an API error (has statusCode), preserve the original error message
|
|
6232
|
+
if (error && typeof error === 'object' && 'statusCode' in error && 'message' in error) {
|
|
6233
|
+
throw new Error(error.message);
|
|
6234
|
+
}
|
|
6187
6235
|
throw this.authenticator.handlePasskeyError(error);
|
|
6188
6236
|
}
|
|
6189
6237
|
}
|
|
6238
|
+
async getDeviceSignature({ message, credentialsKeyPair, deviceKeyPair, }) {
|
|
6239
|
+
let decryptedDevicePrivateKey;
|
|
6240
|
+
if (deviceKeyPair.decryptedPrivateKey) {
|
|
6241
|
+
decryptedDevicePrivateKey = deviceKeyPair.decryptedPrivateKey;
|
|
6242
|
+
}
|
|
6243
|
+
else if (deviceKeyPair.encryptedDevicePrivateKey) {
|
|
6244
|
+
decryptedDevicePrivateKey = await this.cipher.decrypt({
|
|
6245
|
+
cipherText: deviceKeyPair.encryptedDevicePrivateKey,
|
|
6246
|
+
decryptionKey: credentialsKeyPair.privateKey,
|
|
6247
|
+
});
|
|
6248
|
+
}
|
|
6249
|
+
else {
|
|
6250
|
+
throw new Error('Device private key is not available for signing the message.');
|
|
6251
|
+
}
|
|
6252
|
+
const deviceSignature = await this.cipher.sign({
|
|
6253
|
+
message: message,
|
|
6254
|
+
signingKey: decryptedDevicePrivateKey,
|
|
6255
|
+
});
|
|
6256
|
+
return deviceSignature.signature;
|
|
6257
|
+
}
|
|
6190
6258
|
/**
|
|
6191
6259
|
*
|
|
6192
6260
|
* @description Registers a new passkey for the user.
|
|
@@ -6195,27 +6263,38 @@ class PasskeyService {
|
|
|
6195
6263
|
* @returns { AuthResponse } The authentication response containing the access token and user information.
|
|
6196
6264
|
*/
|
|
6197
6265
|
async register({ deviceKeyPair, challengeResponse, }) {
|
|
6198
|
-
|
|
6266
|
+
// const isPrfEnabled = await this.isDevicePrfCompatible();
|
|
6267
|
+
var _a;
|
|
6268
|
+
// if (!isPrfEnabled)
|
|
6269
|
+
// throw new Error('Device is not compatible with this feature. Try using a different authentication method.');
|
|
6199
6270
|
try {
|
|
6200
|
-
const { signature, message } = await this.cipher.sign({
|
|
6201
|
-
message: challengeResponse.message,
|
|
6202
|
-
signingKey: deviceKeyPair.privateKey,
|
|
6203
|
-
});
|
|
6204
6271
|
if (!challengeResponse.registrationOptions)
|
|
6205
6272
|
throw new Error('Passkey challenge could not be retrieved, please try again later.');
|
|
6273
|
+
console.log('SDK::PasskeyService::register:: got challenge', {
|
|
6274
|
+
registrationOptions: challengeResponse.registrationOptions,
|
|
6275
|
+
});
|
|
6206
6276
|
const parsedOptions = this.preparePasskeyCreationOptions(challengeResponse.registrationOptions);
|
|
6207
|
-
|
|
6208
|
-
|
|
6209
|
-
|
|
6210
|
-
},
|
|
6211
|
-
} }) });
|
|
6277
|
+
console.log('SDK::PasskeyService::register:: registering passkey', {
|
|
6278
|
+
parsedOptions,
|
|
6279
|
+
});
|
|
6212
6280
|
const passkeyCredential = await this.authenticator.register({
|
|
6213
|
-
optionsJSON:
|
|
6281
|
+
optionsJSON: parsedOptions,
|
|
6214
6282
|
});
|
|
6215
|
-
|
|
6283
|
+
console.log('SDK::PasskeyService::register:: got passkey credential', {
|
|
6284
|
+
id: passkeyCredential.id,
|
|
6285
|
+
type: passkeyCredential.type,
|
|
6286
|
+
});
|
|
6287
|
+
if (!((_a = passkeyCredential.clientExtensionResults.prf) === null || _a === void 0 ? void 0 : _a.enabled)) {
|
|
6216
6288
|
throw new Error('Device is not compatible with this feature. Try using a different authentication method.');
|
|
6217
6289
|
}
|
|
6218
|
-
|
|
6290
|
+
console.log('SDK::PasskeyService::register:: getting signature', {
|
|
6291
|
+
message: challengeResponse.message,
|
|
6292
|
+
privateKey: deviceKeyPair.privateKey,
|
|
6293
|
+
});
|
|
6294
|
+
const { signature, message } = await this.cipher.sign({
|
|
6295
|
+
message: challengeResponse.message,
|
|
6296
|
+
signingKey: deviceKeyPair.privateKey,
|
|
6297
|
+
});
|
|
6219
6298
|
const signUpResponse = await this.request(AuthRoutes.signUp, {
|
|
6220
6299
|
payload: {
|
|
6221
6300
|
externalUserId: this.userId,
|
|
@@ -6228,6 +6307,7 @@ class PasskeyService {
|
|
|
6228
6307
|
if (signUpResponse.error) {
|
|
6229
6308
|
throw new Error('Passkey authentication failed. Please try again.');
|
|
6230
6309
|
}
|
|
6310
|
+
const credentialsKeyPair = await this.handleCredentialsCreationFromPrfExtension(passkeyCredential);
|
|
6231
6311
|
const encryptedNewDevicePrivateKey = await this.cipher.encrypt({
|
|
6232
6312
|
data: deviceKeyPair.privateKey,
|
|
6233
6313
|
encryptionKey: credentialsKeyPair.publicKey,
|
|
@@ -6243,11 +6323,19 @@ class PasskeyService {
|
|
|
6243
6323
|
return Object.freeze(Object.assign(Object.assign({}, signUpResponse), { prfValue: credentialsKeyPair.prfValue }));
|
|
6244
6324
|
}
|
|
6245
6325
|
catch (error) {
|
|
6326
|
+
console.log('SDK::PasskeyService::register::error', { error, errorCode: error.code, errorMessage: error.message });
|
|
6246
6327
|
// we want to skip handling the error and showing the proper error message for this one.
|
|
6247
6328
|
// this will allow the caller to handle the re authentication more gracefully.
|
|
6248
|
-
if (error && error.code ===
|
|
6329
|
+
if ((error && error.code === AuthenticatorPreviouslyRegisteredError.error) ||
|
|
6330
|
+
error.code === InvalidStateError.error ||
|
|
6331
|
+
error.message === 'The authenticator was previously registered.') {
|
|
6332
|
+
console.log('SDK::PasskeyService::register::ERROR_AUTHENTICATOR_PREVIOUSLY_REGISTERED', true);
|
|
6249
6333
|
throw error;
|
|
6250
6334
|
}
|
|
6335
|
+
// If it's an API error (has statusCode), preserve the original error message
|
|
6336
|
+
if (error && typeof error === 'object' && 'statusCode' in error && 'message' in error) {
|
|
6337
|
+
throw new Error(error.message);
|
|
6338
|
+
}
|
|
6251
6339
|
throw this.authenticator.handlePasskeyError(error);
|
|
6252
6340
|
}
|
|
6253
6341
|
}
|
|
@@ -6259,20 +6347,17 @@ class PasskeyService {
|
|
|
6259
6347
|
async isDevicePrfCompatible() {
|
|
6260
6348
|
var _a;
|
|
6261
6349
|
try {
|
|
6262
|
-
|
|
6263
|
-
|
|
6264
|
-
|
|
6265
|
-
|
|
6266
|
-
|
|
6267
|
-
|
|
6268
|
-
|
|
6269
|
-
|
|
6270
|
-
optionsJSON: parsedOptions,
|
|
6271
|
-
});
|
|
6272
|
-
return (_a = passkeyCredential.clientExtensionResults.prf) === null || _a === void 0 ? void 0 : _a.enabled;
|
|
6350
|
+
// Check if we're in a browser environment and getClientCapabilities is available
|
|
6351
|
+
if (typeof window !== 'undefined' && typeof ((_a = window.PublicKeyCredential) === null || _a === void 0 ? void 0 : _a.getClientCapabilities) === 'function') {
|
|
6352
|
+
const capabilities = await window.PublicKeyCredential.getClientCapabilities();
|
|
6353
|
+
console.log('SDK::PasskeyService::isDevicePrfCompatible::capabilities', capabilities);
|
|
6354
|
+
return capabilities['extension:prf'];
|
|
6355
|
+
}
|
|
6356
|
+
// Fallback: assume PRF is not supported if the API is not available
|
|
6357
|
+
return false;
|
|
6273
6358
|
}
|
|
6274
|
-
catch (
|
|
6275
|
-
return
|
|
6359
|
+
catch (_b) {
|
|
6360
|
+
return false;
|
|
6276
6361
|
}
|
|
6277
6362
|
}
|
|
6278
6363
|
/**
|
|
@@ -6322,20 +6407,31 @@ class PasskeyService {
|
|
|
6322
6407
|
* @returns {Promise<AsymmetricKeyPair>} The credentials key pair.
|
|
6323
6408
|
*/
|
|
6324
6409
|
async handleCredentialsCreationFromPrfExtension(passkeyCredential) {
|
|
6325
|
-
var _a, _b, _c, _d;
|
|
6410
|
+
var _a, _b, _c, _d, _e;
|
|
6326
6411
|
try {
|
|
6327
6412
|
const extensions = passkeyCredential.clientExtensionResults;
|
|
6413
|
+
console.log('SDK::PasskeyService::handleCredentialsCreationFromPrfExtension::extensions', extensions);
|
|
6328
6414
|
if (!((_a = extensions.prf) === null || _a === void 0 ? void 0 : _a.enabled) && !((_c = (_b = extensions.prf) === null || _b === void 0 ? void 0 : _b.results) === null || _c === void 0 ? void 0 : _c.first)) {
|
|
6329
6415
|
throw new Error('Device is not compatible with this feature. Try using a different authentication method.');
|
|
6330
6416
|
}
|
|
6331
|
-
|
|
6417
|
+
logger.debug('SDK::PasskeyService::handleCredentialsCreationFromPrfExtension::prf is enabled', extensions.prf.enabled);
|
|
6418
|
+
if (!((_d = extensions.prf.results) === null || _d === void 0 ? void 0 : _d.first)) {
|
|
6419
|
+
throw new Error('PRF extension did not return any results. Cannot proceed with authentication.');
|
|
6420
|
+
}
|
|
6421
|
+
const prfValue = new Uint8Array((_e = extensions.prf.results) === null || _e === void 0 ? void 0 : _e.first);
|
|
6422
|
+
logger.debug('SDK::PasskeyService::handleCredentialsCreationFromPrfExtension::prfValue', !!prfValue);
|
|
6332
6423
|
const credentialsKeyPair = await this.cipher.getCredentialsKeyPair({
|
|
6333
6424
|
prfValue,
|
|
6334
6425
|
authType: exports.AuthType.Passkey,
|
|
6335
6426
|
});
|
|
6427
|
+
console.log('SDK::PasskeyService::handleCredentialsCreationFromPrfExtension::credentials key pair was created', !!credentialsKeyPair);
|
|
6336
6428
|
return Object.assign(Object.assign({}, credentialsKeyPair), { prfValue });
|
|
6337
6429
|
}
|
|
6338
6430
|
catch (error) {
|
|
6431
|
+
// If it's an API error (has statusCode), preserve the original error message
|
|
6432
|
+
if (error && typeof error === 'object' && 'statusCode' in error && 'message' in error) {
|
|
6433
|
+
throw new Error(error.message);
|
|
6434
|
+
}
|
|
6339
6435
|
throw this.authenticator.handlePasskeyError(error);
|
|
6340
6436
|
}
|
|
6341
6437
|
}
|
|
@@ -6366,9 +6462,6 @@ class AuthService extends Base {
|
|
|
6366
6462
|
this.getUserSalt = this.getUserSalt.bind(this);
|
|
6367
6463
|
this.passkeyService = new PasskeyService(config.userId, this.localStorageService, this.request);
|
|
6368
6464
|
}
|
|
6369
|
-
get authenticationType() {
|
|
6370
|
-
return this.deviceAuthType;
|
|
6371
|
-
}
|
|
6372
6465
|
/**
|
|
6373
6466
|
* @description
|
|
6374
6467
|
* This method is used to check if the user is on a device that supports PRF.
|
|
@@ -6460,7 +6553,9 @@ class AuthService extends Base {
|
|
|
6460
6553
|
*/
|
|
6461
6554
|
async getSignature(deviceAuthKeys, passkeyChallengeType) {
|
|
6462
6555
|
try {
|
|
6463
|
-
|
|
6556
|
+
logger.debug('SDK::AuthService::getSignature::authType', this.deviceAuthType);
|
|
6557
|
+
const challengeType = passkeyChallengeType !== null && passkeyChallengeType !== void 0 ? passkeyChallengeType : exports.PasskeyChallengeType.REGISTRATION;
|
|
6558
|
+
logger.debug('SDK::AuthService::getSignature::challengeType', challengeType);
|
|
6464
6559
|
const response = await this.request(AuthRoutes.signatureMessage, {
|
|
6465
6560
|
payload: {
|
|
6466
6561
|
clientAuthPubKey: deviceAuthKeys.publicKey,
|
|
@@ -6493,12 +6588,12 @@ class AuthService extends Base {
|
|
|
6493
6588
|
* @throws {Error} - Throws an error if the sign-up process fails.
|
|
6494
6589
|
*/
|
|
6495
6590
|
async signUp(input) {
|
|
6591
|
+
logger.info('starting signup');
|
|
6592
|
+
const deviceKeyPair = createIdentity();
|
|
6593
|
+
logger.info('key pair generated', !!deviceKeyPair);
|
|
6594
|
+
let authentication;
|
|
6496
6595
|
try {
|
|
6497
|
-
logger.info('starting signup');
|
|
6498
|
-
const deviceKeyPair = createIdentity();
|
|
6499
|
-
logger.info('key pair generated', !!deviceKeyPair);
|
|
6500
6596
|
const signatureMessageResponse = await this.getSignature(deviceKeyPair, exports.PasskeyChallengeType.REGISTRATION);
|
|
6501
|
-
let authentication;
|
|
6502
6597
|
logger.info('signature has been generated', !!signatureMessageResponse);
|
|
6503
6598
|
switch (this.deviceAuthType) {
|
|
6504
6599
|
case exports.AuthType.Passkey:
|
|
@@ -6522,6 +6617,20 @@ class AuthService extends Base {
|
|
|
6522
6617
|
return Object.freeze(Object.assign(Object.assign({}, authentication), input));
|
|
6523
6618
|
}
|
|
6524
6619
|
catch (error) {
|
|
6620
|
+
console.log('SDK::AuthService::signUp::error', {
|
|
6621
|
+
error,
|
|
6622
|
+
errorCode: error === null || error === void 0 ? void 0 : error.code,
|
|
6623
|
+
errorMessage: error === null || error === void 0 ? void 0 : error.message,
|
|
6624
|
+
});
|
|
6625
|
+
if ((error && error.error === InvalidStateError.error) || error.code === AuthenticatorPreviouslyRegisteredError.error) {
|
|
6626
|
+
console.log('SDK::AuthService::signUp::handling previously registered passkey error');
|
|
6627
|
+
const newChallenge = await this.getSignature(deviceKeyPair, exports.PasskeyChallengeType.AUTHENTICATION);
|
|
6628
|
+
authentication = await this.passkeyService.authenticate({
|
|
6629
|
+
deviceKeyPair: { publicKey: deviceKeyPair.publicKey, decryptedPrivateKey: deviceKeyPair.privateKey },
|
|
6630
|
+
challengeResponse: newChallenge,
|
|
6631
|
+
});
|
|
6632
|
+
return authentication;
|
|
6633
|
+
}
|
|
6525
6634
|
logger.error('SDK::AuthService::signUp::error', error);
|
|
6526
6635
|
throw new Error(error.message || 'Error signing up, please try again later.');
|
|
6527
6636
|
}
|
|
@@ -6631,23 +6740,24 @@ class AuthService extends Base {
|
|
|
6631
6740
|
async handleSignInWithPasskey({ input }) {
|
|
6632
6741
|
let authentication;
|
|
6633
6742
|
try {
|
|
6743
|
+
const passkeyCredential = await this.localStorageService.fetch(exports.LocalStorageItems.PasskeyCredential);
|
|
6634
6744
|
const encryptedDevicePrivateKey = await this.localStorageService.fetch(exports.LocalStorageItems.EncryptedDevicePrivateKey);
|
|
6635
6745
|
let devicePublicKey = await this.localStorageService.fetch(exports.LocalStorageItems.ClientAuthPublicKey);
|
|
6636
6746
|
let deviceKeyPair;
|
|
6637
6747
|
// This logic needs to change and depend on data from server.
|
|
6638
|
-
if (!
|
|
6748
|
+
if (!passkeyCredential) {
|
|
6749
|
+
console.debug('SDK::AuthService::handleSignInWithPasskey:: creating new key pair');
|
|
6639
6750
|
deviceKeyPair = createIdentity();
|
|
6640
6751
|
devicePublicKey = deviceKeyPair.publicKey;
|
|
6641
6752
|
await this.localStorageService.save(exports.LocalStorageItems.ClientAuthPublicKey, devicePublicKey);
|
|
6642
|
-
const signatureMessage = await this.getSignature(deviceKeyPair, exports.PasskeyChallengeType.REGISTRATION);
|
|
6643
6753
|
authentication = await this.passkeyService.addNewPasskey({
|
|
6644
6754
|
deviceKeyPair,
|
|
6645
|
-
challengeResponse: signatureMessage,
|
|
6646
6755
|
getSignature: this.getSignature.bind(this),
|
|
6647
6756
|
});
|
|
6648
|
-
logger.
|
|
6757
|
+
logger.debug('SDK::AuthService::handleSignInWithPasskey:: passkey registration finished', authentication);
|
|
6649
6758
|
}
|
|
6650
6759
|
else {
|
|
6760
|
+
logger.debug('SDK::AuthService::handleSignInWithPasskey:: using existing key pair');
|
|
6651
6761
|
// calling this function outside the this.getSignature as the latter accepts a key pair object, but at this stage we only have the public key.
|
|
6652
6762
|
// The private key is still encrypted with the passkey, which we are trying to retrieve.
|
|
6653
6763
|
const challengeResponse = await this.request(AuthRoutes.signatureMessage, {
|
|
@@ -6656,14 +6766,18 @@ class AuthService extends Base {
|
|
|
6656
6766
|
if (!challengeResponse)
|
|
6657
6767
|
throw new Error('Signature message could not be retrieved, please try again later.');
|
|
6658
6768
|
if (challengeResponse.error)
|
|
6659
|
-
throw new Error(challengeResponse.error);
|
|
6769
|
+
throw new Error(`Challenge error: ${challengeResponse.error}`);
|
|
6660
6770
|
authentication = await this.passkeyService.authenticate({
|
|
6661
|
-
deviceKeyPair: {
|
|
6771
|
+
deviceKeyPair: {
|
|
6772
|
+
publicKey: devicePublicKey,
|
|
6773
|
+
encryptedDevicePrivateKey: safeJsonParse(encryptedDevicePrivateKey),
|
|
6774
|
+
},
|
|
6662
6775
|
challengeResponse,
|
|
6663
6776
|
});
|
|
6777
|
+
logger.debug('SDK::AuthService::handleSignInWithPasskey:: passkey authentication finished', authentication);
|
|
6664
6778
|
}
|
|
6665
6779
|
if (authentication.error)
|
|
6666
|
-
throw new Error(authentication.error);
|
|
6780
|
+
throw new Error(`Authentication error: ${authentication.error}`);
|
|
6667
6781
|
return Object.assign(Object.assign(Object.assign({}, authentication), { prfValue: authentication.prfValue }), input);
|
|
6668
6782
|
}
|
|
6669
6783
|
catch (error) {
|
|
@@ -7175,6 +7289,7 @@ class WalletService extends Base {
|
|
|
7175
7289
|
this.authService = new AuthService(config);
|
|
7176
7290
|
this.handlers = new WalletHandlersService(config);
|
|
7177
7291
|
this.userId = config.userId;
|
|
7292
|
+
this.passkeyService = new PasskeyService(config.userId, this.localStorageService, this.request);
|
|
7178
7293
|
}
|
|
7179
7294
|
/**
|
|
7180
7295
|
* @public
|
|
@@ -7484,10 +7599,6 @@ class WalletService extends Base {
|
|
|
7484
7599
|
salt: input.authenticationOptions.user.clientSalt,
|
|
7485
7600
|
prfValue: input.authenticationOptions.prfValue,
|
|
7486
7601
|
});
|
|
7487
|
-
await this.authService.storeDeviceKeyPair({
|
|
7488
|
-
deviceAuthKeyPair,
|
|
7489
|
-
credentialsKeyPair,
|
|
7490
|
-
});
|
|
7491
7602
|
let recoverWithSeedPhraseResponse;
|
|
7492
7603
|
if (input.seedPhrase) {
|
|
7493
7604
|
const encryptedSeedPhrase = await encryptWithPublicKey(wallabyPublicKey, input.seedPhrase);
|
|
@@ -7502,7 +7613,7 @@ class WalletService extends Base {
|
|
|
7502
7613
|
encryptedSeed: encryptWithPublicKey(deviceAuthKeyPair.publicKey, input.seedPhrase), // usually this comes back from the API wrapped with the device pub.
|
|
7503
7614
|
devicePrivateKey: deviceAuthKeyPair.privateKey,
|
|
7504
7615
|
credentialsKeyPair,
|
|
7505
|
-
storeSeedPhrase:
|
|
7616
|
+
storeSeedPhrase: true,
|
|
7506
7617
|
});
|
|
7507
7618
|
}
|
|
7508
7619
|
if ((_a = recoverWithSeedPhraseResponse.shares) === null || _a === void 0 ? void 0 : _a.length) {
|
|
@@ -7883,11 +7994,11 @@ class WalletService extends Base {
|
|
|
7883
7994
|
cipherText: parsedBackupShare,
|
|
7884
7995
|
decryptionKey: credentialsKeyPair.privateKey,
|
|
7885
7996
|
});
|
|
7886
|
-
const
|
|
7997
|
+
const wallabyBoundBackupShare = safeJsonParse(decryptedOnceBackupShare);
|
|
7887
7998
|
return {
|
|
7888
7999
|
walletId,
|
|
7889
8000
|
backupUrl,
|
|
7890
|
-
encryptedShares: [wallabyBoundPrimaryShare,
|
|
8001
|
+
encryptedShares: [wallabyBoundPrimaryShare, wallabyBoundBackupShare],
|
|
7891
8002
|
};
|
|
7892
8003
|
}
|
|
7893
8004
|
/**
|
|
@@ -8287,6 +8398,93 @@ class WalletService extends Base {
|
|
|
8287
8398
|
hasShares: sharesEncryptedWithWallabyPubKey.length > 0,
|
|
8288
8399
|
};
|
|
8289
8400
|
}
|
|
8401
|
+
/**
|
|
8402
|
+
*
|
|
8403
|
+
* @param input
|
|
8404
|
+
* - { string } password - current wallet password
|
|
8405
|
+
* - { string } walletId - the wallet ID for the user
|
|
8406
|
+
* @returns { boolean } whether the operation was successful
|
|
8407
|
+
*/
|
|
8408
|
+
async convertToPasskey(input) {
|
|
8409
|
+
try {
|
|
8410
|
+
const encryptedPriv = await this.localStorageService.fetch(exports.LocalStorageItems.EncryptedDevicePrivateKey);
|
|
8411
|
+
const encryptedSeed = await this.localStorageService.fetch(exports.LocalStorageItems.EncryptedStandardSeedPhrase, {
|
|
8412
|
+
walletId: input.walletId,
|
|
8413
|
+
});
|
|
8414
|
+
const clientSalt = await this.authService.getUserSalt();
|
|
8415
|
+
const passwordCredentialsKeyPair = await this.cipher.getCredentialsKeyPair({
|
|
8416
|
+
password: input.password,
|
|
8417
|
+
salt: clientSalt,
|
|
8418
|
+
authType: exports.AuthType.Password,
|
|
8419
|
+
});
|
|
8420
|
+
let decryptedClientAuthPrivKey;
|
|
8421
|
+
const isPasswordValid = await this.authService.validatePassword({ password: input.password, salt: clientSalt });
|
|
8422
|
+
if (!isPasswordValid) {
|
|
8423
|
+
logger.error('SDK::AuthService::handleSignInWithPassword::error', 'Incorrect password');
|
|
8424
|
+
throw new Error('Incorrect password, please try again.');
|
|
8425
|
+
}
|
|
8426
|
+
if (encryptedPriv) {
|
|
8427
|
+
const encryptedDevicePrivateKey = safeJsonParse(encryptedPriv);
|
|
8428
|
+
decryptedClientAuthPrivKey = await this.cipher.decrypt({
|
|
8429
|
+
cipherText: encryptedDevicePrivateKey,
|
|
8430
|
+
decryptionKey: passwordCredentialsKeyPair.privateKey,
|
|
8431
|
+
});
|
|
8432
|
+
}
|
|
8433
|
+
else {
|
|
8434
|
+
// Handle v1 keys - get the decrypted private key directly
|
|
8435
|
+
decryptedClientAuthPrivKey = await this.localStorageService.getDecryptedV1PrivateKey(input.password);
|
|
8436
|
+
}
|
|
8437
|
+
if (!decryptedClientAuthPrivKey) {
|
|
8438
|
+
logger.error('SDK::AuthService::handleSignInWithPassword::error', 'Device private key could not be decrypted');
|
|
8439
|
+
throw new Error('Device private key could not be decrypted');
|
|
8440
|
+
}
|
|
8441
|
+
const clientPublicKey = publicKeyByPrivateKey(decryptedClientAuthPrivKey);
|
|
8442
|
+
console.log('SDK::WalletService::convertToPasskey::authType', this.deviceAuthType);
|
|
8443
|
+
const authentication = await this.passkeyService.addNewPasskey({
|
|
8444
|
+
deviceKeyPair: {
|
|
8445
|
+
publicKey: clientPublicKey,
|
|
8446
|
+
privateKey: decryptedClientAuthPrivKey,
|
|
8447
|
+
},
|
|
8448
|
+
getSignature: this.authService.getSignature.bind(this),
|
|
8449
|
+
});
|
|
8450
|
+
if (authentication.error)
|
|
8451
|
+
throw new Error(authentication.error);
|
|
8452
|
+
const decryptedSeedPhrase = await this.cipher.displayStoredData({
|
|
8453
|
+
storedEncryptedData: safeJsonParse(encryptedSeed),
|
|
8454
|
+
encryptedDevicePrivateKey: safeJsonParse(encryptedPriv),
|
|
8455
|
+
options: {
|
|
8456
|
+
// prfValue: authentication.prfValue,
|
|
8457
|
+
authType: exports.AuthType.Password,
|
|
8458
|
+
password: input.password,
|
|
8459
|
+
salt: clientSalt,
|
|
8460
|
+
},
|
|
8461
|
+
});
|
|
8462
|
+
const importResult = await this.handlers.handleImportWallet({
|
|
8463
|
+
publicKey: clientPublicKey,
|
|
8464
|
+
privateKey: decryptedClientAuthPrivKey,
|
|
8465
|
+
}, {
|
|
8466
|
+
authenticationOptions: authentication,
|
|
8467
|
+
seedPhrase: decryptedSeedPhrase,
|
|
8468
|
+
storeSeedPhrase: false,
|
|
8469
|
+
returnWalletOption: exports.ReturnWalletOption.ReturnOnlyEncryptedShares, // always only return the encrypted shares
|
|
8470
|
+
keyShareOptions: {
|
|
8471
|
+
threshold: 2,
|
|
8472
|
+
numberOfKeyShares: 3,
|
|
8473
|
+
numberOfSharesReturned: 2,
|
|
8474
|
+
storeOneKeyShareWithWallaby: true,
|
|
8475
|
+
},
|
|
8476
|
+
});
|
|
8477
|
+
if (importResult.error)
|
|
8478
|
+
throw new Error(importResult.error);
|
|
8479
|
+
await this.localStorageService.delete(exports.LocalStorageItems.EncryptedStandardSeedPhrase, { walletId: input.walletId });
|
|
8480
|
+
logger.info('SDK::WalletService::convertToPasskey::Seed phrase removed from device storage after conversion to passkey');
|
|
8481
|
+
return { authentication, seedPhrase: decryptedSeedPhrase };
|
|
8482
|
+
}
|
|
8483
|
+
catch (error) {
|
|
8484
|
+
logger.error('SDK::AuthService::convertToPasskey::error', error);
|
|
8485
|
+
throw error;
|
|
8486
|
+
}
|
|
8487
|
+
}
|
|
8290
8488
|
}
|
|
8291
8489
|
__decorate([
|
|
8292
8490
|
WithLock('create'),
|
|
@@ -8353,11 +8551,11 @@ class WalletDataService extends Base {
|
|
|
8353
8551
|
/**
|
|
8354
8552
|
*
|
|
8355
8553
|
* @public
|
|
8356
|
-
*
|
|
8554
|
+
* Fetches the balance for a specific token in a wallet.
|
|
8357
8555
|
* @param { string } address Wallet address
|
|
8358
8556
|
* @param { string } symbol Token symbol
|
|
8359
8557
|
* @param { BlockchainName } chainName the chain name enum. i.e. 'ETHEREUM', 'BITCOIN'
|
|
8360
|
-
* @returns {
|
|
8558
|
+
* @returns { TokenBalanceResponse } The wallet has been created successfully
|
|
8361
8559
|
*/
|
|
8362
8560
|
async getTokenBalance({ address, symbol, tokenStandard, chainName, }) {
|
|
8363
8561
|
try {
|
|
@@ -8619,7 +8817,6 @@ class WalletDataService extends Base {
|
|
|
8619
8817
|
}
|
|
8620
8818
|
}
|
|
8621
8819
|
|
|
8622
|
-
// import jwt, { SignOptions } from 'jsonwebtoken';
|
|
8623
8820
|
class Utils extends Base {
|
|
8624
8821
|
constructor(config) {
|
|
8625
8822
|
super(config);
|
|
@@ -8628,6 +8825,7 @@ class Utils extends Base {
|
|
|
8628
8825
|
* Decrypts user private key
|
|
8629
8826
|
* @param password
|
|
8630
8827
|
* @returns { string | undefined } It returns the decrypted private key as a string or undefined if it can't decrypt it or find it
|
|
8828
|
+
* @deprecated This method is deprecated and will be removed in future versions.
|
|
8631
8829
|
*/
|
|
8632
8830
|
this.getDecryptedPrivateKey = async (password) => {
|
|
8633
8831
|
const privateKey = await this.localStorageService.fetch(exports.LocalStorageItems.EncryptedDevicePrivateKey);
|
|
@@ -8642,6 +8840,9 @@ class Utils extends Base {
|
|
|
8642
8840
|
return undefined;
|
|
8643
8841
|
}
|
|
8644
8842
|
};
|
|
8843
|
+
/**
|
|
8844
|
+
* @deprecated This method is deprecated and will be removed in future versions.
|
|
8845
|
+
*/
|
|
8645
8846
|
this.decryptDevicePrivateKey = ({ encryptedPrivateKey, password }) => {
|
|
8646
8847
|
const devicePrivateKey = cryptoJs.AES.decrypt(encryptedPrivateKey, password).toString(cryptoJs.enc.Utf8);
|
|
8647
8848
|
if (devicePrivateKey !== '') {
|
|
@@ -8658,6 +8859,7 @@ class Utils extends Base {
|
|
|
8658
8859
|
* @param { string } password
|
|
8659
8860
|
* @param { SeedPhraseType } seedPhraseType
|
|
8660
8861
|
* @returns { UtilsResponse } It returns the decrypted seed phrase as a string or undefined if it can't decrypt it or find it
|
|
8862
|
+
* @deprecated This method is deprecated and will be removed in future versions.
|
|
8661
8863
|
*/
|
|
8662
8864
|
async decryptSeedPhrase({ password }) {
|
|
8663
8865
|
var _a;
|
|
@@ -9000,7 +9202,7 @@ class System extends Base {
|
|
|
9000
9202
|
switch (blockchain) {
|
|
9001
9203
|
case exports.BlockchainName.Algorand:
|
|
9002
9204
|
case exports.BlockchainName.Bitcoin:
|
|
9003
|
-
throw new Error('This blockchain
|
|
9205
|
+
throw new Error('This blockchain does not support smart contracts.');
|
|
9004
9206
|
case exports.BlockchainName.Sui:
|
|
9005
9207
|
if (suiObjectId && contractAddress) {
|
|
9006
9208
|
throw new Error('You can only provide either suiObjectId or contractAddress');
|
|
@@ -9258,7 +9460,7 @@ class Transactions extends Base {
|
|
|
9258
9460
|
}
|
|
9259
9461
|
else if (hasShares) {
|
|
9260
9462
|
transferResponse = await this.request(TransactionsRoutes.transferWithShares, {
|
|
9261
|
-
payload: Object.assign(Object.assign({}, signatureMessage), { clientAuthPubKey: deviceAuthPublicKey, encryptedShares: sharesEncryptedWithWallabyPubKey,
|
|
9463
|
+
payload: Object.assign(Object.assign({}, signatureMessage), { clientAuthPubKey: deviceAuthPublicKey, encryptedShares: sharesEncryptedWithWallabyPubKey, originAddress,
|
|
9262
9464
|
recipientAddress,
|
|
9263
9465
|
assetId,
|
|
9264
9466
|
amount, reference: reference || uuid.v4(), memo }),
|
|
@@ -9267,7 +9469,9 @@ class Transactions extends Base {
|
|
|
9267
9469
|
else {
|
|
9268
9470
|
throw new Error('No valid seed option found on this device.');
|
|
9269
9471
|
}
|
|
9270
|
-
if (!transferResponse ||
|
|
9472
|
+
if (!transferResponse ||
|
|
9473
|
+
transferResponse.error ||
|
|
9474
|
+
(typeof transferResponse === 'object' && Object.keys(transferResponse).length === 0)) {
|
|
9271
9475
|
throw new Error(transferResponse === null || transferResponse === void 0 ? void 0 : transferResponse.error);
|
|
9272
9476
|
}
|
|
9273
9477
|
return transferResponse;
|
|
@@ -9469,6 +9673,34 @@ class Wallaby {
|
|
|
9469
9673
|
}
|
|
9470
9674
|
}
|
|
9471
9675
|
|
|
9676
|
+
exports.AndroidVersionNotSupportedError = AndroidVersionNotSupportedError;
|
|
9677
|
+
exports.AuthenticatorGeneralError = AuthenticatorGeneralError;
|
|
9678
|
+
exports.AuthenticatorMissingDiscoverableCredentialSupportError = AuthenticatorMissingDiscoverableCredentialSupportError;
|
|
9679
|
+
exports.AuthenticatorMissingUserVerificationSupportError = AuthenticatorMissingUserVerificationSupportError;
|
|
9680
|
+
exports.AuthenticatorNoSupportedPubKeyCredParamsAlgError = AuthenticatorNoSupportedPubKeyCredParamsAlgError;
|
|
9681
|
+
exports.AuthenticatorNotRegisteredError = AuthenticatorNotRegisteredError;
|
|
9682
|
+
exports.AuthenticatorPreviouslyRegisteredError = AuthenticatorPreviouslyRegisteredError;
|
|
9683
|
+
exports.AutoRegisterUserVerificationFailureError = AutoRegisterUserVerificationFailureError;
|
|
9684
|
+
exports.BadConfiguration = BadConfiguration;
|
|
9685
|
+
exports.CeremonyAbortedError = CeremonyAbortedError;
|
|
9686
|
+
exports.IOSVersionNotSupportedError = IOSVersionNotSupportedError;
|
|
9687
|
+
exports.InterruptedError = InterruptedError;
|
|
9688
|
+
exports.InvalidChallengeError = InvalidChallengeError;
|
|
9689
|
+
exports.InvalidDomainError = InvalidDomainError;
|
|
9690
|
+
exports.InvalidRpIdError = InvalidRpIdError;
|
|
9691
|
+
exports.InvalidStateError = InvalidStateError;
|
|
9692
|
+
exports.InvalidUserIdError = InvalidUserIdError;
|
|
9693
|
+
exports.InvalidUserIdLengthError = InvalidUserIdLengthError;
|
|
9694
|
+
exports.MalformedPubKeyCredParamsError = MalformedPubKeyCredParamsError;
|
|
9695
|
+
exports.NativeError = NativeError;
|
|
9696
|
+
exports.NoCredentialsError = NoCredentialsError;
|
|
9697
|
+
exports.NotAllowedError = NotAllowedError;
|
|
9698
|
+
exports.PasskeyErrorCodes = PasskeyErrorCodes;
|
|
9699
|
+
exports.PassthroughSeeCausePropertyError = PassthroughSeeCausePropertyError;
|
|
9700
|
+
exports.RequestFailedError = RequestFailedError;
|
|
9701
|
+
exports.TimeoutError = TimeoutError;
|
|
9702
|
+
exports.UnknownError = UnknownError;
|
|
9703
|
+
exports.UserCancelledError = UserCancelledError;
|
|
9472
9704
|
exports.Wallaby = Wallaby;
|
|
9473
9705
|
exports.createIdentity = createIdentity;
|
|
9474
9706
|
exports.decryptWithPrivateKey = decryptWithPrivateKey;
|