wallaby-cash 2.0.1-alpha.35 → 2.0.1-alpha.36
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 +542 -311
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +514 -312
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +514 -312
- 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
|
|
@@ -4852,10 +4988,10 @@ class StorageService {
|
|
|
4852
4988
|
if (!(options === null || options === void 0 ? void 0 : options.walletId)) {
|
|
4853
4989
|
throw new Error(`A walletId is required to fetch: ${key}`);
|
|
4854
4990
|
}
|
|
4855
|
-
storageKey = `
|
|
4991
|
+
storageKey = `wsdk:v2:${this.shortenedEnv}:${key}:${this.userId}:${options.walletId}`;
|
|
4856
4992
|
}
|
|
4857
4993
|
else {
|
|
4858
|
-
storageKey = `
|
|
4994
|
+
storageKey = `wsdk:v2:${this.shortenedEnv}:${key}:${this.userId}`;
|
|
4859
4995
|
}
|
|
4860
4996
|
const item = await this.getItem(storageKey);
|
|
4861
4997
|
if (!item) {
|
|
@@ -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;
|
|
@@ -4878,10 +5021,10 @@ class StorageService {
|
|
|
4878
5021
|
if (!(options === null || options === void 0 ? void 0 : options.walletId)) {
|
|
4879
5022
|
throw new Error(`A walletId is required to save: ${key}`);
|
|
4880
5023
|
}
|
|
4881
|
-
storageKey = `
|
|
5024
|
+
storageKey = `wsdk:v2:${this.shortenedEnv}:${key}:${this.userId}:${options.walletId}`;
|
|
4882
5025
|
}
|
|
4883
5026
|
else {
|
|
4884
|
-
storageKey = `
|
|
5027
|
+
storageKey = `wsdk:v2:${this.shortenedEnv}:${key}:${this.userId}`;
|
|
4885
5028
|
}
|
|
4886
5029
|
let valueToStore;
|
|
4887
5030
|
if (this._keysProtectedByMasterKey.includes(key)) {
|
|
@@ -4902,10 +5045,10 @@ class StorageService {
|
|
|
4902
5045
|
if (!(options === null || options === void 0 ? void 0 : options.walletId)) {
|
|
4903
5046
|
throw new Error(`A walletId is required to delete: ${key}`);
|
|
4904
5047
|
}
|
|
4905
|
-
storageKey = `
|
|
5048
|
+
storageKey = `wsdk:v2:${this.shortenedEnv}:${key}:${this.userId}:${options.walletId}`;
|
|
4906
5049
|
}
|
|
4907
5050
|
else {
|
|
4908
|
-
storageKey = `
|
|
5051
|
+
storageKey = `wsdk:v2:${this.shortenedEnv}:${key}:${this.userId}`;
|
|
4909
5052
|
}
|
|
4910
5053
|
return await this.removeItem(storageKey);
|
|
4911
5054
|
}
|
|
@@ -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) {
|
|
@@ -5977,36 +5988,35 @@ class Authenticator {
|
|
|
5977
5988
|
*/
|
|
5978
5989
|
handlePasskeyError(error) {
|
|
5979
5990
|
logger.error('SDK::Authenticator::handlePasskeyError', error);
|
|
5980
|
-
console.error('SDK::Authenticator::handlePasskeyError::code', error === null || error === void 0 ? void 0 : error.code);
|
|
5981
5991
|
if (error instanceof WebAuthn__namespace.WebAuthnError) {
|
|
5982
|
-
|
|
5983
|
-
return this.throwPasskeyError(error.code);
|
|
5992
|
+
logger.debug('SDK::Authenticator::handlePasskeyError - WebAuthnError', error);
|
|
5993
|
+
return this.throwPasskeyError({ errorCode: error.code });
|
|
5984
5994
|
}
|
|
5985
5995
|
else if (error instanceof Error) {
|
|
5986
|
-
|
|
5987
|
-
return this.throwPasskeyError(error.message
|
|
5996
|
+
logger.debug('SDK::Authenticator::handlePasskeyError - Error', error);
|
|
5997
|
+
return this.throwPasskeyError({ errorMessage: error.message });
|
|
5988
5998
|
}
|
|
5989
5999
|
else if (typeof error === 'object' && error.error && error.message) {
|
|
5990
|
-
|
|
5991
|
-
return this.throwPasskeyError(error.error);
|
|
6000
|
+
logger.debug('SDK::Authenticator::handlePasskeyError - Object', error);
|
|
6001
|
+
return this.throwPasskeyError({ errorCode: error.error, errorMessage: error.message });
|
|
5992
6002
|
}
|
|
5993
6003
|
else if (typeof error === 'string') {
|
|
5994
|
-
|
|
5995
|
-
return this.throwPasskeyError(error);
|
|
6004
|
+
logger.debug('SDK::Authenticator::handlePasskeyError - String', error);
|
|
6005
|
+
return this.throwPasskeyError({ errorMessage: error });
|
|
5996
6006
|
}
|
|
5997
6007
|
else {
|
|
5998
|
-
|
|
5999
|
-
return this.throwPasskeyError();
|
|
6008
|
+
logger.debug('SDK::Authenticator::handlePasskeyError - Unknown', error);
|
|
6009
|
+
return this.throwPasskeyError({});
|
|
6000
6010
|
}
|
|
6001
6011
|
}
|
|
6002
|
-
throwPasskeyError(errorCode) {
|
|
6003
|
-
var _a;
|
|
6012
|
+
throwPasskeyError({ errorCode, errorMessage }) {
|
|
6013
|
+
var _a, _b;
|
|
6004
6014
|
logger.error('SDK::Authenticator::throwPasskeyError', errorCode);
|
|
6005
6015
|
const errorToThrow = PasskeyErrorCodes.find((error) => {
|
|
6006
6016
|
return error.error === errorCode;
|
|
6007
6017
|
});
|
|
6008
6018
|
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);
|
|
6019
|
+
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
6020
|
}
|
|
6011
6021
|
}
|
|
6012
6022
|
|
|
@@ -6021,22 +6031,18 @@ class PasskeyService {
|
|
|
6021
6031
|
preparePasskeyRequestOptions(options) {
|
|
6022
6032
|
var _a, _b, _c, _d, _e, _f;
|
|
6023
6033
|
const prfExtensionEvaluation = ((_b = (_a = options.extensions) === null || _a === void 0 ? void 0 : _a.prf.eval) === null || _b === void 0 ? void 0 : _b.base64)
|
|
6024
|
-
?
|
|
6034
|
+
? WebAuthn__namespace.base64URLStringToBuffer(options.extensions.prf.eval.base64)
|
|
6025
6035
|
: ((_d = (_c = options.extensions) === null || _c === void 0 ? void 0 : _c.prf.eval) === null || _d === void 0 ? void 0 : _d.first) instanceof ArrayBuffer
|
|
6026
6036
|
? new Uint8Array(options.extensions.prf.eval.first)
|
|
6027
6037
|
: typeof ((_f = (_e = options.extensions) === null || _e === void 0 ? void 0 : _e.prf.eval) === null || _f === void 0 ? void 0 : _f.first) === 'object'
|
|
6028
6038
|
? new Uint8Array(Object.values(options.extensions.prf.eval.first))
|
|
6029
6039
|
: 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: {
|
|
6040
|
+
const parsedOptions = Object.assign(Object.assign({}, options), { extensions: Object.assign(Object.assign({}, options.extensions), { prf: {
|
|
6035
6041
|
eval: {
|
|
6036
6042
|
first: prfExtensionEvaluation,
|
|
6037
6043
|
},
|
|
6038
|
-
}
|
|
6039
|
-
|
|
6044
|
+
} }) });
|
|
6045
|
+
console.log('SDK::PasskeyService::preparePasskeyRequestOptions::parsedOptions', parsedOptions);
|
|
6040
6046
|
// While the authenticator still works with the prf and would return the response (if any),
|
|
6041
6047
|
// the library `@simplewebauthn/browser` does not support the prf extension in its type intentionally.
|
|
6042
6048
|
// > "Using the prf extension does not fall under the simple use of webauthn."
|
|
@@ -6045,7 +6051,7 @@ class PasskeyService {
|
|
|
6045
6051
|
preparePasskeyCreationOptions(options) {
|
|
6046
6052
|
var _a, _b, _c, _d, _e, _f;
|
|
6047
6053
|
const prfExtensionEvaluation = ((_b = (_a = options.extensions) === null || _a === void 0 ? void 0 : _a.prf.eval) === null || _b === void 0 ? void 0 : _b.base64)
|
|
6048
|
-
?
|
|
6054
|
+
? WebAuthn__namespace.base64URLStringToBuffer(options.extensions.prf.eval.base64)
|
|
6049
6055
|
: ((_d = (_c = options.extensions) === null || _c === void 0 ? void 0 : _c.prf.eval) === null || _d === void 0 ? void 0 : _d.first) instanceof ArrayBuffer
|
|
6050
6056
|
? new Uint8Array(options.extensions.prf.eval.first)
|
|
6051
6057
|
: 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 +6062,7 @@ class PasskeyService {
|
|
|
6056
6062
|
first: prfExtensionEvaluation,
|
|
6057
6063
|
},
|
|
6058
6064
|
} }) });
|
|
6065
|
+
console.log('SDK::PasskeyService::preparePasskeyRequestOptions::parsedOptions', parsedOptions);
|
|
6059
6066
|
return parsedOptions;
|
|
6060
6067
|
}
|
|
6061
6068
|
/**
|
|
@@ -6064,73 +6071,88 @@ class PasskeyService {
|
|
|
6064
6071
|
* @param { SignatureMessageResponse } challengeResponse
|
|
6065
6072
|
* @returns { AuthResponse } The authentication response containing the access token and user information.
|
|
6066
6073
|
*/
|
|
6067
|
-
async addNewPasskey({ deviceKeyPair,
|
|
6074
|
+
async addNewPasskey({ deviceKeyPair, getSignature, }) {
|
|
6068
6075
|
try {
|
|
6076
|
+
// const isPrfEnabled = await this.isDevicePrfCompatible();
|
|
6077
|
+
// if (!isPrfEnabled)
|
|
6078
|
+
// throw new Error('Device is not compatible with this feature. Try using a different authentication method.');
|
|
6069
6079
|
let passkeyCredential;
|
|
6070
|
-
|
|
6071
|
-
|
|
6072
|
-
|
|
6073
|
-
|
|
6074
|
-
|
|
6075
|
-
|
|
6076
|
-
|
|
6077
|
-
|
|
6078
|
-
|
|
6079
|
-
|
|
6080
|
-
|
|
6081
|
-
|
|
6082
|
-
|
|
6083
|
-
|
|
6084
|
-
|
|
6085
|
-
|
|
6086
|
-
|
|
6080
|
+
let signInResponse;
|
|
6081
|
+
try {
|
|
6082
|
+
const registrationChallengeResponse = await getSignature(deviceKeyPair, exports.PasskeyChallengeType.REGISTRATION);
|
|
6083
|
+
if (!registrationChallengeResponse.registrationOptions)
|
|
6084
|
+
throw new Error('Passkey challenge could not be retrieved, please try again later.');
|
|
6085
|
+
const parsedOptions = this.preparePasskeyCreationOptions(registrationChallengeResponse.registrationOptions);
|
|
6086
|
+
passkeyCredential = await this.authenticator.register({
|
|
6087
|
+
optionsJSON: parsedOptions,
|
|
6088
|
+
});
|
|
6089
|
+
// before we sign the user in, we need to make sure the prf extension is enabled and we have a value.
|
|
6090
|
+
const credentialsKeyPair = await this.handleCredentialsCreationFromPrfExtension(passkeyCredential);
|
|
6091
|
+
signInResponse = await this.request(AuthRoutes.signIn, {
|
|
6092
|
+
payload: {
|
|
6093
|
+
externalUserId: this.userId,
|
|
6094
|
+
message: registrationChallengeResponse.message,
|
|
6095
|
+
clientAuthPubKey: deviceKeyPair.publicKey,
|
|
6096
|
+
signature: registrationChallengeResponse.signature,
|
|
6097
|
+
passkeyRegistrationResponse: passkeyCredential,
|
|
6098
|
+
},
|
|
6099
|
+
});
|
|
6100
|
+
const encryptedNewDevicePrivateKey = await this.cipher.encrypt({
|
|
6101
|
+
data: deviceKeyPair.privateKey,
|
|
6102
|
+
encryptionKey: credentialsKeyPair.publicKey,
|
|
6103
|
+
});
|
|
6104
|
+
await this.handleStoringData({
|
|
6105
|
+
authenticationResponse: signInResponse,
|
|
6106
|
+
deviceKeyPair: {
|
|
6107
|
+
publicKey: deviceKeyPair.publicKey,
|
|
6108
|
+
encryptedDevicePrivateKey: encryptedNewDevicePrivateKey,
|
|
6109
|
+
},
|
|
6110
|
+
passkeyCredential,
|
|
6111
|
+
});
|
|
6112
|
+
return Object.assign(Object.assign({}, signInResponse), { prfValue: credentialsKeyPair.prfValue });
|
|
6087
6113
|
}
|
|
6088
|
-
|
|
6089
|
-
|
|
6090
|
-
|
|
6114
|
+
catch (error) {
|
|
6115
|
+
logger.error('SDK::PasskeyService::addNewPasskey::error', error);
|
|
6116
|
+
if (error && error.code === AuthenticatorPreviouslyRegisteredError.error) {
|
|
6117
|
+
const authenticationChallengeResponse = await getSignature(deviceKeyPair, exports.PasskeyChallengeType.AUTHENTICATION);
|
|
6118
|
+
if (!authenticationChallengeResponse.authenticationOptions)
|
|
6119
|
+
throw new Error('Passkey challenge could not be retrieved, please try again later.');
|
|
6120
|
+
const parsedOptions = this.preparePasskeyRequestOptions(authenticationChallengeResponse.authenticationOptions);
|
|
6091
6121
|
passkeyCredential = await this.authenticator.authenticate({
|
|
6092
6122
|
optionsJSON: parsedOptions,
|
|
6093
6123
|
});
|
|
6124
|
+
signInResponse = await this.request(AuthRoutes.signIn, {
|
|
6125
|
+
payload: {
|
|
6126
|
+
externalUserId: this.userId,
|
|
6127
|
+
message: authenticationChallengeResponse.message,
|
|
6128
|
+
clientAuthPubKey: deviceKeyPair.publicKey,
|
|
6129
|
+
signature: authenticationChallengeResponse.signature,
|
|
6130
|
+
passkeyAuthenticationResponse: passkeyCredential,
|
|
6131
|
+
},
|
|
6132
|
+
});
|
|
6133
|
+
const credentialsKeyPair = await this.handleCredentialsCreationFromPrfExtension(passkeyCredential);
|
|
6134
|
+
const encryptedNewDevicePrivateKey = await this.cipher.encrypt({
|
|
6135
|
+
data: deviceKeyPair.privateKey,
|
|
6136
|
+
encryptionKey: credentialsKeyPair.publicKey,
|
|
6137
|
+
});
|
|
6138
|
+
await this.handleStoringData({
|
|
6139
|
+
authenticationResponse: signInResponse,
|
|
6140
|
+
deviceKeyPair: {
|
|
6141
|
+
publicKey: deviceKeyPair.publicKey,
|
|
6142
|
+
encryptedDevicePrivateKey: encryptedNewDevicePrivateKey,
|
|
6143
|
+
},
|
|
6144
|
+
passkeyCredential,
|
|
6145
|
+
});
|
|
6146
|
+
return Object.assign(Object.assign({}, signInResponse), { prfValue: credentialsKeyPair.prfValue });
|
|
6094
6147
|
}
|
|
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.');
|
|
6148
|
+
throw error;
|
|
6118
6149
|
}
|
|
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
6150
|
}
|
|
6133
6151
|
catch (error) {
|
|
6152
|
+
// If it's an API error (has statusCode), preserve the original error message
|
|
6153
|
+
if (error && typeof error === 'object' && 'statusCode' in error && 'message' in error) {
|
|
6154
|
+
throw new Error(error.message);
|
|
6155
|
+
}
|
|
6134
6156
|
throw this.authenticator.handlePasskeyError(error);
|
|
6135
6157
|
}
|
|
6136
6158
|
}
|
|
@@ -6142,7 +6164,10 @@ class PasskeyService {
|
|
|
6142
6164
|
* @returns { AuthResponse } The authentication response containing the access token and user information.
|
|
6143
6165
|
*/
|
|
6144
6166
|
async authenticate({ deviceKeyPair, challengeResponse, }) {
|
|
6167
|
+
// const isPrfEnabled = await this.isDevicePrfCompatible();
|
|
6145
6168
|
var _a, _b;
|
|
6169
|
+
// if (!isPrfEnabled)
|
|
6170
|
+
// throw new Error('Device is not compatible with this feature. Try using a different authentication method.');
|
|
6146
6171
|
try {
|
|
6147
6172
|
if (!challengeResponse.authenticationOptions)
|
|
6148
6173
|
throw new Error('Passkey challenge could not be retrieved, please try again later.');
|
|
@@ -6156,19 +6181,20 @@ class PasskeyService {
|
|
|
6156
6181
|
optionsJSON: updatedOptions,
|
|
6157
6182
|
});
|
|
6158
6183
|
const credentialsKeyPair = await this.handleCredentialsCreationFromPrfExtension(passkeyCredential);
|
|
6159
|
-
|
|
6160
|
-
|
|
6161
|
-
|
|
6162
|
-
|
|
6163
|
-
|
|
6164
|
-
|
|
6165
|
-
|
|
6166
|
-
|
|
6184
|
+
// this isn't always present, when authenticating sometimes we need the PRF value first to decrypt the device private key.
|
|
6185
|
+
// before we're able to get a signature.
|
|
6186
|
+
const deviceSignature = challengeResponse.signature
|
|
6187
|
+
? challengeResponse.signature
|
|
6188
|
+
: await this.getDeviceSignature({
|
|
6189
|
+
message: challengeResponse.message,
|
|
6190
|
+
credentialsKeyPair,
|
|
6191
|
+
deviceKeyPair,
|
|
6192
|
+
});
|
|
6167
6193
|
const signInResponse = await this.request(AuthRoutes.signIn, {
|
|
6168
6194
|
payload: {
|
|
6169
6195
|
externalUserId: this.userId,
|
|
6170
|
-
message,
|
|
6171
|
-
signature,
|
|
6196
|
+
message: challengeResponse.message,
|
|
6197
|
+
signature: deviceSignature,
|
|
6172
6198
|
clientAuthPubKey: deviceKeyPair.publicKey,
|
|
6173
6199
|
passkeyAuthenticationResponse: passkeyCredential,
|
|
6174
6200
|
},
|
|
@@ -6176,17 +6202,58 @@ class PasskeyService {
|
|
|
6176
6202
|
if (signInResponse.error) {
|
|
6177
6203
|
throw new Error('Passkey authentication failed. Please try again.');
|
|
6178
6204
|
}
|
|
6205
|
+
const devicePrivateKeyForStorage = deviceKeyPair.decryptedPrivateKey
|
|
6206
|
+
? deviceKeyPair.decryptedPrivateKey
|
|
6207
|
+
: deviceKeyPair.encryptedDevicePrivateKey
|
|
6208
|
+
? await this.cipher.decrypt({
|
|
6209
|
+
cipherText: deviceKeyPair.encryptedDevicePrivateKey,
|
|
6210
|
+
decryptionKey: credentialsKeyPair.privateKey,
|
|
6211
|
+
})
|
|
6212
|
+
: undefined;
|
|
6213
|
+
if (!devicePrivateKeyForStorage)
|
|
6214
|
+
throw new Error('Device private key is not available for storage.');
|
|
6215
|
+
const encryptedPrivKey = await this.cipher.encrypt({
|
|
6216
|
+
data: devicePrivateKeyForStorage,
|
|
6217
|
+
encryptionKey: credentialsKeyPair.publicKey,
|
|
6218
|
+
});
|
|
6179
6219
|
await this.handleStoringData({
|
|
6180
6220
|
authenticationResponse: signInResponse,
|
|
6181
|
-
deviceKeyPair
|
|
6221
|
+
deviceKeyPair: {
|
|
6222
|
+
publicKey: deviceKeyPair.publicKey,
|
|
6223
|
+
encryptedDevicePrivateKey: encryptedPrivKey,
|
|
6224
|
+
},
|
|
6182
6225
|
passkeyCredential,
|
|
6183
6226
|
});
|
|
6184
6227
|
return Object.freeze(Object.assign(Object.assign({}, signInResponse), { prfValue: credentialsKeyPair.prfValue }));
|
|
6185
6228
|
}
|
|
6186
6229
|
catch (error) {
|
|
6230
|
+
// If it's an API error (has statusCode), preserve the original error message
|
|
6231
|
+
if (error && typeof error === 'object' && 'statusCode' in error && 'message' in error) {
|
|
6232
|
+
throw new Error(error.message);
|
|
6233
|
+
}
|
|
6187
6234
|
throw this.authenticator.handlePasskeyError(error);
|
|
6188
6235
|
}
|
|
6189
6236
|
}
|
|
6237
|
+
async getDeviceSignature({ message, credentialsKeyPair, deviceKeyPair, }) {
|
|
6238
|
+
let decryptedDevicePrivateKey;
|
|
6239
|
+
if (deviceKeyPair.decryptedPrivateKey) {
|
|
6240
|
+
decryptedDevicePrivateKey = deviceKeyPair.decryptedPrivateKey;
|
|
6241
|
+
}
|
|
6242
|
+
else if (deviceKeyPair.encryptedDevicePrivateKey) {
|
|
6243
|
+
decryptedDevicePrivateKey = await this.cipher.decrypt({
|
|
6244
|
+
cipherText: deviceKeyPair.encryptedDevicePrivateKey,
|
|
6245
|
+
decryptionKey: credentialsKeyPair.privateKey,
|
|
6246
|
+
});
|
|
6247
|
+
}
|
|
6248
|
+
else {
|
|
6249
|
+
throw new Error('Device private key is not available for signing the message.');
|
|
6250
|
+
}
|
|
6251
|
+
const deviceSignature = await this.cipher.sign({
|
|
6252
|
+
message: message,
|
|
6253
|
+
signingKey: decryptedDevicePrivateKey,
|
|
6254
|
+
});
|
|
6255
|
+
return deviceSignature.signature;
|
|
6256
|
+
}
|
|
6190
6257
|
/**
|
|
6191
6258
|
*
|
|
6192
6259
|
* @description Registers a new passkey for the user.
|
|
@@ -6195,27 +6262,38 @@ class PasskeyService {
|
|
|
6195
6262
|
* @returns { AuthResponse } The authentication response containing the access token and user information.
|
|
6196
6263
|
*/
|
|
6197
6264
|
async register({ deviceKeyPair, challengeResponse, }) {
|
|
6198
|
-
|
|
6265
|
+
// const isPrfEnabled = await this.isDevicePrfCompatible();
|
|
6266
|
+
var _a;
|
|
6267
|
+
// if (!isPrfEnabled)
|
|
6268
|
+
// throw new Error('Device is not compatible with this feature. Try using a different authentication method.');
|
|
6199
6269
|
try {
|
|
6200
|
-
const { signature, message } = await this.cipher.sign({
|
|
6201
|
-
message: challengeResponse.message,
|
|
6202
|
-
signingKey: deviceKeyPair.privateKey,
|
|
6203
|
-
});
|
|
6204
6270
|
if (!challengeResponse.registrationOptions)
|
|
6205
6271
|
throw new Error('Passkey challenge could not be retrieved, please try again later.');
|
|
6272
|
+
console.log('SDK::PasskeyService::register:: got challenge', {
|
|
6273
|
+
registrationOptions: challengeResponse.registrationOptions,
|
|
6274
|
+
});
|
|
6206
6275
|
const parsedOptions = this.preparePasskeyCreationOptions(challengeResponse.registrationOptions);
|
|
6207
|
-
|
|
6208
|
-
|
|
6209
|
-
|
|
6210
|
-
},
|
|
6211
|
-
} }) });
|
|
6276
|
+
console.log('SDK::PasskeyService::register:: registering passkey', {
|
|
6277
|
+
parsedOptions,
|
|
6278
|
+
});
|
|
6212
6279
|
const passkeyCredential = await this.authenticator.register({
|
|
6213
|
-
optionsJSON:
|
|
6280
|
+
optionsJSON: parsedOptions,
|
|
6214
6281
|
});
|
|
6215
|
-
|
|
6282
|
+
console.log('SDK::PasskeyService::register:: got passkey credential', {
|
|
6283
|
+
id: passkeyCredential.id,
|
|
6284
|
+
type: passkeyCredential.type,
|
|
6285
|
+
});
|
|
6286
|
+
if (!((_a = passkeyCredential.clientExtensionResults.prf) === null || _a === void 0 ? void 0 : _a.enabled)) {
|
|
6216
6287
|
throw new Error('Device is not compatible with this feature. Try using a different authentication method.');
|
|
6217
6288
|
}
|
|
6218
|
-
|
|
6289
|
+
console.log('SDK::PasskeyService::register:: getting signature', {
|
|
6290
|
+
message: challengeResponse.message,
|
|
6291
|
+
privateKey: deviceKeyPair.privateKey,
|
|
6292
|
+
});
|
|
6293
|
+
const { signature, message } = await this.cipher.sign({
|
|
6294
|
+
message: challengeResponse.message,
|
|
6295
|
+
signingKey: deviceKeyPair.privateKey,
|
|
6296
|
+
});
|
|
6219
6297
|
const signUpResponse = await this.request(AuthRoutes.signUp, {
|
|
6220
6298
|
payload: {
|
|
6221
6299
|
externalUserId: this.userId,
|
|
@@ -6228,6 +6306,7 @@ class PasskeyService {
|
|
|
6228
6306
|
if (signUpResponse.error) {
|
|
6229
6307
|
throw new Error('Passkey authentication failed. Please try again.');
|
|
6230
6308
|
}
|
|
6309
|
+
const credentialsKeyPair = await this.handleCredentialsCreationFromPrfExtension(passkeyCredential);
|
|
6231
6310
|
const encryptedNewDevicePrivateKey = await this.cipher.encrypt({
|
|
6232
6311
|
data: deviceKeyPair.privateKey,
|
|
6233
6312
|
encryptionKey: credentialsKeyPair.publicKey,
|
|
@@ -6243,11 +6322,19 @@ class PasskeyService {
|
|
|
6243
6322
|
return Object.freeze(Object.assign(Object.assign({}, signUpResponse), { prfValue: credentialsKeyPair.prfValue }));
|
|
6244
6323
|
}
|
|
6245
6324
|
catch (error) {
|
|
6325
|
+
console.log('SDK::PasskeyService::register::error', { error, errorCode: error.code, errorMessage: error.message });
|
|
6246
6326
|
// we want to skip handling the error and showing the proper error message for this one.
|
|
6247
6327
|
// this will allow the caller to handle the re authentication more gracefully.
|
|
6248
|
-
if (error && error.code ===
|
|
6328
|
+
if ((error && error.code === AuthenticatorPreviouslyRegisteredError.error) ||
|
|
6329
|
+
error.code === InvalidStateError.error ||
|
|
6330
|
+
error.message === 'The authenticator was previously registered.') {
|
|
6331
|
+
console.log('SDK::PasskeyService::register::ERROR_AUTHENTICATOR_PREVIOUSLY_REGISTERED', true);
|
|
6249
6332
|
throw error;
|
|
6250
6333
|
}
|
|
6334
|
+
// If it's an API error (has statusCode), preserve the original error message
|
|
6335
|
+
if (error && typeof error === 'object' && 'statusCode' in error && 'message' in error) {
|
|
6336
|
+
throw new Error(error.message);
|
|
6337
|
+
}
|
|
6251
6338
|
throw this.authenticator.handlePasskeyError(error);
|
|
6252
6339
|
}
|
|
6253
6340
|
}
|
|
@@ -6259,20 +6346,17 @@ class PasskeyService {
|
|
|
6259
6346
|
async isDevicePrfCompatible() {
|
|
6260
6347
|
var _a;
|
|
6261
6348
|
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;
|
|
6349
|
+
// Check if we're in a browser environment and getClientCapabilities is available
|
|
6350
|
+
if (typeof window !== 'undefined' && typeof ((_a = window.PublicKeyCredential) === null || _a === void 0 ? void 0 : _a.getClientCapabilities) === 'function') {
|
|
6351
|
+
const capabilities = await window.PublicKeyCredential.getClientCapabilities();
|
|
6352
|
+
console.log('SDK::PasskeyService::isDevicePrfCompatible::capabilities', capabilities);
|
|
6353
|
+
return capabilities['extension:prf'];
|
|
6354
|
+
}
|
|
6355
|
+
// Fallback: assume PRF is not supported if the API is not available
|
|
6356
|
+
return false;
|
|
6273
6357
|
}
|
|
6274
|
-
catch (
|
|
6275
|
-
return
|
|
6358
|
+
catch (_b) {
|
|
6359
|
+
return false;
|
|
6276
6360
|
}
|
|
6277
6361
|
}
|
|
6278
6362
|
/**
|
|
@@ -6322,20 +6406,31 @@ class PasskeyService {
|
|
|
6322
6406
|
* @returns {Promise<AsymmetricKeyPair>} The credentials key pair.
|
|
6323
6407
|
*/
|
|
6324
6408
|
async handleCredentialsCreationFromPrfExtension(passkeyCredential) {
|
|
6325
|
-
var _a, _b, _c, _d;
|
|
6409
|
+
var _a, _b, _c, _d, _e;
|
|
6326
6410
|
try {
|
|
6327
6411
|
const extensions = passkeyCredential.clientExtensionResults;
|
|
6412
|
+
console.log('SDK::PasskeyService::handleCredentialsCreationFromPrfExtension::extensions', extensions);
|
|
6328
6413
|
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
6414
|
throw new Error('Device is not compatible with this feature. Try using a different authentication method.');
|
|
6330
6415
|
}
|
|
6331
|
-
|
|
6416
|
+
logger.debug('SDK::PasskeyService::handleCredentialsCreationFromPrfExtension::prf is enabled', extensions.prf.enabled);
|
|
6417
|
+
if (!((_d = extensions.prf.results) === null || _d === void 0 ? void 0 : _d.first)) {
|
|
6418
|
+
throw new Error('PRF extension did not return any results. Cannot proceed with authentication.');
|
|
6419
|
+
}
|
|
6420
|
+
const prfValue = new Uint8Array((_e = extensions.prf.results) === null || _e === void 0 ? void 0 : _e.first);
|
|
6421
|
+
logger.debug('SDK::PasskeyService::handleCredentialsCreationFromPrfExtension::prfValue', !!prfValue);
|
|
6332
6422
|
const credentialsKeyPair = await this.cipher.getCredentialsKeyPair({
|
|
6333
6423
|
prfValue,
|
|
6334
6424
|
authType: exports.AuthType.Passkey,
|
|
6335
6425
|
});
|
|
6426
|
+
console.log('SDK::PasskeyService::handleCredentialsCreationFromPrfExtension::credentials key pair was created', !!credentialsKeyPair);
|
|
6336
6427
|
return Object.assign(Object.assign({}, credentialsKeyPair), { prfValue });
|
|
6337
6428
|
}
|
|
6338
6429
|
catch (error) {
|
|
6430
|
+
// If it's an API error (has statusCode), preserve the original error message
|
|
6431
|
+
if (error && typeof error === 'object' && 'statusCode' in error && 'message' in error) {
|
|
6432
|
+
throw new Error(error.message);
|
|
6433
|
+
}
|
|
6339
6434
|
throw this.authenticator.handlePasskeyError(error);
|
|
6340
6435
|
}
|
|
6341
6436
|
}
|
|
@@ -6366,9 +6461,6 @@ class AuthService extends Base {
|
|
|
6366
6461
|
this.getUserSalt = this.getUserSalt.bind(this);
|
|
6367
6462
|
this.passkeyService = new PasskeyService(config.userId, this.localStorageService, this.request);
|
|
6368
6463
|
}
|
|
6369
|
-
get authenticationType() {
|
|
6370
|
-
return this.deviceAuthType;
|
|
6371
|
-
}
|
|
6372
6464
|
/**
|
|
6373
6465
|
* @description
|
|
6374
6466
|
* This method is used to check if the user is on a device that supports PRF.
|
|
@@ -6460,7 +6552,9 @@ class AuthService extends Base {
|
|
|
6460
6552
|
*/
|
|
6461
6553
|
async getSignature(deviceAuthKeys, passkeyChallengeType) {
|
|
6462
6554
|
try {
|
|
6463
|
-
|
|
6555
|
+
logger.debug('SDK::AuthService::getSignature::authType', this.deviceAuthType);
|
|
6556
|
+
const challengeType = passkeyChallengeType !== null && passkeyChallengeType !== void 0 ? passkeyChallengeType : exports.PasskeyChallengeType.REGISTRATION;
|
|
6557
|
+
logger.debug('SDK::AuthService::getSignature::challengeType', challengeType);
|
|
6464
6558
|
const response = await this.request(AuthRoutes.signatureMessage, {
|
|
6465
6559
|
payload: {
|
|
6466
6560
|
clientAuthPubKey: deviceAuthKeys.publicKey,
|
|
@@ -6493,12 +6587,12 @@ class AuthService extends Base {
|
|
|
6493
6587
|
* @throws {Error} - Throws an error if the sign-up process fails.
|
|
6494
6588
|
*/
|
|
6495
6589
|
async signUp(input) {
|
|
6590
|
+
logger.info('starting signup');
|
|
6591
|
+
const deviceKeyPair = createIdentity();
|
|
6592
|
+
logger.info('key pair generated', !!deviceKeyPair);
|
|
6593
|
+
let authentication;
|
|
6496
6594
|
try {
|
|
6497
|
-
logger.info('starting signup');
|
|
6498
|
-
const deviceKeyPair = createIdentity();
|
|
6499
|
-
logger.info('key pair generated', !!deviceKeyPair);
|
|
6500
6595
|
const signatureMessageResponse = await this.getSignature(deviceKeyPair, exports.PasskeyChallengeType.REGISTRATION);
|
|
6501
|
-
let authentication;
|
|
6502
6596
|
logger.info('signature has been generated', !!signatureMessageResponse);
|
|
6503
6597
|
switch (this.deviceAuthType) {
|
|
6504
6598
|
case exports.AuthType.Passkey:
|
|
@@ -6522,6 +6616,20 @@ class AuthService extends Base {
|
|
|
6522
6616
|
return Object.freeze(Object.assign(Object.assign({}, authentication), input));
|
|
6523
6617
|
}
|
|
6524
6618
|
catch (error) {
|
|
6619
|
+
console.log('SDK::AuthService::signUp::error', {
|
|
6620
|
+
error,
|
|
6621
|
+
errorCode: error === null || error === void 0 ? void 0 : error.code,
|
|
6622
|
+
errorMessage: error === null || error === void 0 ? void 0 : error.message,
|
|
6623
|
+
});
|
|
6624
|
+
if ((error && error.error === InvalidStateError.error) || error.code === AuthenticatorPreviouslyRegisteredError.error) {
|
|
6625
|
+
console.log('SDK::AuthService::signUp::handling previously registered passkey error');
|
|
6626
|
+
const newChallenge = await this.getSignature(deviceKeyPair, exports.PasskeyChallengeType.AUTHENTICATION);
|
|
6627
|
+
authentication = await this.passkeyService.authenticate({
|
|
6628
|
+
deviceKeyPair: { publicKey: deviceKeyPair.publicKey, decryptedPrivateKey: deviceKeyPair.privateKey },
|
|
6629
|
+
challengeResponse: newChallenge,
|
|
6630
|
+
});
|
|
6631
|
+
return authentication;
|
|
6632
|
+
}
|
|
6525
6633
|
logger.error('SDK::AuthService::signUp::error', error);
|
|
6526
6634
|
throw new Error(error.message || 'Error signing up, please try again later.');
|
|
6527
6635
|
}
|
|
@@ -6631,23 +6739,24 @@ class AuthService extends Base {
|
|
|
6631
6739
|
async handleSignInWithPasskey({ input }) {
|
|
6632
6740
|
let authentication;
|
|
6633
6741
|
try {
|
|
6742
|
+
const passkeyCredential = await this.localStorageService.fetch(exports.LocalStorageItems.PasskeyCredential);
|
|
6634
6743
|
const encryptedDevicePrivateKey = await this.localStorageService.fetch(exports.LocalStorageItems.EncryptedDevicePrivateKey);
|
|
6635
6744
|
let devicePublicKey = await this.localStorageService.fetch(exports.LocalStorageItems.ClientAuthPublicKey);
|
|
6636
6745
|
let deviceKeyPair;
|
|
6637
6746
|
// This logic needs to change and depend on data from server.
|
|
6638
|
-
if (!
|
|
6747
|
+
if (!passkeyCredential) {
|
|
6748
|
+
console.debug('SDK::AuthService::handleSignInWithPasskey:: creating new key pair');
|
|
6639
6749
|
deviceKeyPair = createIdentity();
|
|
6640
6750
|
devicePublicKey = deviceKeyPair.publicKey;
|
|
6641
6751
|
await this.localStorageService.save(exports.LocalStorageItems.ClientAuthPublicKey, devicePublicKey);
|
|
6642
|
-
const signatureMessage = await this.getSignature(deviceKeyPair, exports.PasskeyChallengeType.REGISTRATION);
|
|
6643
6752
|
authentication = await this.passkeyService.addNewPasskey({
|
|
6644
6753
|
deviceKeyPair,
|
|
6645
|
-
challengeResponse: signatureMessage,
|
|
6646
6754
|
getSignature: this.getSignature.bind(this),
|
|
6647
6755
|
});
|
|
6648
|
-
logger.
|
|
6756
|
+
logger.debug('SDK::AuthService::handleSignInWithPasskey:: passkey registration finished', authentication);
|
|
6649
6757
|
}
|
|
6650
6758
|
else {
|
|
6759
|
+
logger.debug('SDK::AuthService::handleSignInWithPasskey:: using existing key pair');
|
|
6651
6760
|
// 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
6761
|
// The private key is still encrypted with the passkey, which we are trying to retrieve.
|
|
6653
6762
|
const challengeResponse = await this.request(AuthRoutes.signatureMessage, {
|
|
@@ -6656,14 +6765,18 @@ class AuthService extends Base {
|
|
|
6656
6765
|
if (!challengeResponse)
|
|
6657
6766
|
throw new Error('Signature message could not be retrieved, please try again later.');
|
|
6658
6767
|
if (challengeResponse.error)
|
|
6659
|
-
throw new Error(challengeResponse.error);
|
|
6768
|
+
throw new Error(`Challenge error: ${challengeResponse.error}`);
|
|
6660
6769
|
authentication = await this.passkeyService.authenticate({
|
|
6661
|
-
deviceKeyPair: {
|
|
6770
|
+
deviceKeyPair: {
|
|
6771
|
+
publicKey: devicePublicKey,
|
|
6772
|
+
encryptedDevicePrivateKey: safeJsonParse(encryptedDevicePrivateKey),
|
|
6773
|
+
},
|
|
6662
6774
|
challengeResponse,
|
|
6663
6775
|
});
|
|
6776
|
+
logger.debug('SDK::AuthService::handleSignInWithPasskey:: passkey authentication finished', authentication);
|
|
6664
6777
|
}
|
|
6665
6778
|
if (authentication.error)
|
|
6666
|
-
throw new Error(authentication.error);
|
|
6779
|
+
throw new Error(`Authentication error: ${authentication.error}`);
|
|
6667
6780
|
return Object.assign(Object.assign(Object.assign({}, authentication), { prfValue: authentication.prfValue }), input);
|
|
6668
6781
|
}
|
|
6669
6782
|
catch (error) {
|
|
@@ -7175,6 +7288,7 @@ class WalletService extends Base {
|
|
|
7175
7288
|
this.authService = new AuthService(config);
|
|
7176
7289
|
this.handlers = new WalletHandlersService(config);
|
|
7177
7290
|
this.userId = config.userId;
|
|
7291
|
+
this.passkeyService = new PasskeyService(config.userId, this.localStorageService, this.request);
|
|
7178
7292
|
}
|
|
7179
7293
|
/**
|
|
7180
7294
|
* @public
|
|
@@ -7484,10 +7598,6 @@ class WalletService extends Base {
|
|
|
7484
7598
|
salt: input.authenticationOptions.user.clientSalt,
|
|
7485
7599
|
prfValue: input.authenticationOptions.prfValue,
|
|
7486
7600
|
});
|
|
7487
|
-
await this.authService.storeDeviceKeyPair({
|
|
7488
|
-
deviceAuthKeyPair,
|
|
7489
|
-
credentialsKeyPair,
|
|
7490
|
-
});
|
|
7491
7601
|
let recoverWithSeedPhraseResponse;
|
|
7492
7602
|
if (input.seedPhrase) {
|
|
7493
7603
|
const encryptedSeedPhrase = await encryptWithPublicKey(wallabyPublicKey, input.seedPhrase);
|
|
@@ -7502,7 +7612,7 @@ class WalletService extends Base {
|
|
|
7502
7612
|
encryptedSeed: encryptWithPublicKey(deviceAuthKeyPair.publicKey, input.seedPhrase), // usually this comes back from the API wrapped with the device pub.
|
|
7503
7613
|
devicePrivateKey: deviceAuthKeyPair.privateKey,
|
|
7504
7614
|
credentialsKeyPair,
|
|
7505
|
-
storeSeedPhrase:
|
|
7615
|
+
storeSeedPhrase: true,
|
|
7506
7616
|
});
|
|
7507
7617
|
}
|
|
7508
7618
|
if ((_a = recoverWithSeedPhraseResponse.shares) === null || _a === void 0 ? void 0 : _a.length) {
|
|
@@ -7883,11 +7993,11 @@ class WalletService extends Base {
|
|
|
7883
7993
|
cipherText: parsedBackupShare,
|
|
7884
7994
|
decryptionKey: credentialsKeyPair.privateKey,
|
|
7885
7995
|
});
|
|
7886
|
-
const
|
|
7996
|
+
const wallabyBoundBackupShare = safeJsonParse(decryptedOnceBackupShare);
|
|
7887
7997
|
return {
|
|
7888
7998
|
walletId,
|
|
7889
7999
|
backupUrl,
|
|
7890
|
-
encryptedShares: [wallabyBoundPrimaryShare,
|
|
8000
|
+
encryptedShares: [wallabyBoundPrimaryShare, wallabyBoundBackupShare],
|
|
7891
8001
|
};
|
|
7892
8002
|
}
|
|
7893
8003
|
/**
|
|
@@ -8287,6 +8397,93 @@ class WalletService extends Base {
|
|
|
8287
8397
|
hasShares: sharesEncryptedWithWallabyPubKey.length > 0,
|
|
8288
8398
|
};
|
|
8289
8399
|
}
|
|
8400
|
+
/**
|
|
8401
|
+
*
|
|
8402
|
+
* @param input
|
|
8403
|
+
* - { string } password - current wallet password
|
|
8404
|
+
* - { string } walletId - the wallet ID for the user
|
|
8405
|
+
* @returns { boolean } whether the operation was successful
|
|
8406
|
+
*/
|
|
8407
|
+
async convertToPasskey(input) {
|
|
8408
|
+
try {
|
|
8409
|
+
const encryptedPriv = await this.localStorageService.fetch(exports.LocalStorageItems.EncryptedDevicePrivateKey);
|
|
8410
|
+
const encryptedSeed = await this.localStorageService.fetch(exports.LocalStorageItems.EncryptedStandardSeedPhrase, {
|
|
8411
|
+
walletId: input.walletId,
|
|
8412
|
+
});
|
|
8413
|
+
const clientSalt = await this.authService.getUserSalt();
|
|
8414
|
+
const passwordCredentialsKeyPair = await this.cipher.getCredentialsKeyPair({
|
|
8415
|
+
password: input.password,
|
|
8416
|
+
salt: clientSalt,
|
|
8417
|
+
authType: exports.AuthType.Password,
|
|
8418
|
+
});
|
|
8419
|
+
let decryptedClientAuthPrivKey;
|
|
8420
|
+
const isPasswordValid = await this.authService.validatePassword({ password: input.password, salt: clientSalt });
|
|
8421
|
+
if (!isPasswordValid) {
|
|
8422
|
+
logger.error('SDK::AuthService::handleSignInWithPassword::error', 'Incorrect password');
|
|
8423
|
+
throw new Error('Incorrect password, please try again.');
|
|
8424
|
+
}
|
|
8425
|
+
if (encryptedPriv) {
|
|
8426
|
+
const encryptedDevicePrivateKey = safeJsonParse(encryptedPriv);
|
|
8427
|
+
decryptedClientAuthPrivKey = await this.cipher.decrypt({
|
|
8428
|
+
cipherText: encryptedDevicePrivateKey,
|
|
8429
|
+
decryptionKey: passwordCredentialsKeyPair.privateKey,
|
|
8430
|
+
});
|
|
8431
|
+
}
|
|
8432
|
+
else {
|
|
8433
|
+
// Handle v1 keys - get the decrypted private key directly
|
|
8434
|
+
decryptedClientAuthPrivKey = await this.localStorageService.getDecryptedV1PrivateKey(input.password);
|
|
8435
|
+
}
|
|
8436
|
+
if (!decryptedClientAuthPrivKey) {
|
|
8437
|
+
logger.error('SDK::AuthService::handleSignInWithPassword::error', 'Device private key could not be decrypted');
|
|
8438
|
+
throw new Error('Device private key could not be decrypted');
|
|
8439
|
+
}
|
|
8440
|
+
const clientPublicKey = publicKeyByPrivateKey(decryptedClientAuthPrivKey);
|
|
8441
|
+
console.log('SDK::WalletService::convertToPasskey::authType', this.deviceAuthType);
|
|
8442
|
+
const authentication = await this.passkeyService.addNewPasskey({
|
|
8443
|
+
deviceKeyPair: {
|
|
8444
|
+
publicKey: clientPublicKey,
|
|
8445
|
+
privateKey: decryptedClientAuthPrivKey,
|
|
8446
|
+
},
|
|
8447
|
+
getSignature: this.authService.getSignature.bind(this),
|
|
8448
|
+
});
|
|
8449
|
+
if (authentication.error)
|
|
8450
|
+
throw new Error(authentication.error);
|
|
8451
|
+
const decryptedSeedPhrase = await this.cipher.displayStoredData({
|
|
8452
|
+
storedEncryptedData: safeJsonParse(encryptedSeed),
|
|
8453
|
+
encryptedDevicePrivateKey: safeJsonParse(encryptedPriv),
|
|
8454
|
+
options: {
|
|
8455
|
+
// prfValue: authentication.prfValue,
|
|
8456
|
+
authType: exports.AuthType.Password,
|
|
8457
|
+
password: input.password,
|
|
8458
|
+
salt: clientSalt,
|
|
8459
|
+
},
|
|
8460
|
+
});
|
|
8461
|
+
const importResult = await this.handlers.handleImportWallet({
|
|
8462
|
+
publicKey: clientPublicKey,
|
|
8463
|
+
privateKey: decryptedClientAuthPrivKey,
|
|
8464
|
+
}, {
|
|
8465
|
+
authenticationOptions: authentication,
|
|
8466
|
+
seedPhrase: decryptedSeedPhrase,
|
|
8467
|
+
storeSeedPhrase: false,
|
|
8468
|
+
returnWalletOption: exports.ReturnWalletOption.ReturnOnlyEncryptedShares, // always only return the encrypted shares
|
|
8469
|
+
keyShareOptions: {
|
|
8470
|
+
threshold: 2,
|
|
8471
|
+
numberOfKeyShares: 3,
|
|
8472
|
+
numberOfSharesReturned: 2,
|
|
8473
|
+
storeOneKeyShareWithWallaby: true,
|
|
8474
|
+
},
|
|
8475
|
+
});
|
|
8476
|
+
if (importResult.error)
|
|
8477
|
+
throw new Error(importResult.error);
|
|
8478
|
+
await this.localStorageService.delete(exports.LocalStorageItems.EncryptedStandardSeedPhrase, { walletId: input.walletId });
|
|
8479
|
+
logger.info('SDK::WalletService::convertToPasskey::Seed phrase removed from device storage after conversion to passkey');
|
|
8480
|
+
return { authentication, seedPhrase: decryptedSeedPhrase };
|
|
8481
|
+
}
|
|
8482
|
+
catch (error) {
|
|
8483
|
+
logger.error('SDK::AuthService::convertToPasskey::error', error);
|
|
8484
|
+
throw error;
|
|
8485
|
+
}
|
|
8486
|
+
}
|
|
8290
8487
|
}
|
|
8291
8488
|
__decorate([
|
|
8292
8489
|
WithLock('create'),
|
|
@@ -8353,11 +8550,11 @@ class WalletDataService extends Base {
|
|
|
8353
8550
|
/**
|
|
8354
8551
|
*
|
|
8355
8552
|
* @public
|
|
8356
|
-
*
|
|
8553
|
+
* Fetches the balance for a specific token in a wallet.
|
|
8357
8554
|
* @param { string } address Wallet address
|
|
8358
8555
|
* @param { string } symbol Token symbol
|
|
8359
8556
|
* @param { BlockchainName } chainName the chain name enum. i.e. 'ETHEREUM', 'BITCOIN'
|
|
8360
|
-
* @returns {
|
|
8557
|
+
* @returns { TokenBalanceResponse } The wallet has been created successfully
|
|
8361
8558
|
*/
|
|
8362
8559
|
async getTokenBalance({ address, symbol, tokenStandard, chainName, }) {
|
|
8363
8560
|
try {
|
|
@@ -8619,7 +8816,6 @@ class WalletDataService extends Base {
|
|
|
8619
8816
|
}
|
|
8620
8817
|
}
|
|
8621
8818
|
|
|
8622
|
-
// import jwt, { SignOptions } from 'jsonwebtoken';
|
|
8623
8819
|
class Utils extends Base {
|
|
8624
8820
|
constructor(config) {
|
|
8625
8821
|
super(config);
|
|
@@ -8628,6 +8824,7 @@ class Utils extends Base {
|
|
|
8628
8824
|
* Decrypts user private key
|
|
8629
8825
|
* @param password
|
|
8630
8826
|
* @returns { string | undefined } It returns the decrypted private key as a string or undefined if it can't decrypt it or find it
|
|
8827
|
+
* @deprecated This method is deprecated and will be removed in future versions.
|
|
8631
8828
|
*/
|
|
8632
8829
|
this.getDecryptedPrivateKey = async (password) => {
|
|
8633
8830
|
const privateKey = await this.localStorageService.fetch(exports.LocalStorageItems.EncryptedDevicePrivateKey);
|
|
@@ -8642,6 +8839,9 @@ class Utils extends Base {
|
|
|
8642
8839
|
return undefined;
|
|
8643
8840
|
}
|
|
8644
8841
|
};
|
|
8842
|
+
/**
|
|
8843
|
+
* @deprecated This method is deprecated and will be removed in future versions.
|
|
8844
|
+
*/
|
|
8645
8845
|
this.decryptDevicePrivateKey = ({ encryptedPrivateKey, password }) => {
|
|
8646
8846
|
const devicePrivateKey = cryptoJs.AES.decrypt(encryptedPrivateKey, password).toString(cryptoJs.enc.Utf8);
|
|
8647
8847
|
if (devicePrivateKey !== '') {
|
|
@@ -8658,6 +8858,7 @@ class Utils extends Base {
|
|
|
8658
8858
|
* @param { string } password
|
|
8659
8859
|
* @param { SeedPhraseType } seedPhraseType
|
|
8660
8860
|
* @returns { UtilsResponse } It returns the decrypted seed phrase as a string or undefined if it can't decrypt it or find it
|
|
8861
|
+
* @deprecated This method is deprecated and will be removed in future versions.
|
|
8661
8862
|
*/
|
|
8662
8863
|
async decryptSeedPhrase({ password }) {
|
|
8663
8864
|
var _a;
|
|
@@ -9000,7 +9201,7 @@ class System extends Base {
|
|
|
9000
9201
|
switch (blockchain) {
|
|
9001
9202
|
case exports.BlockchainName.Algorand:
|
|
9002
9203
|
case exports.BlockchainName.Bitcoin:
|
|
9003
|
-
throw new Error('This blockchain
|
|
9204
|
+
throw new Error('This blockchain does not support smart contracts.');
|
|
9004
9205
|
case exports.BlockchainName.Sui:
|
|
9005
9206
|
if (suiObjectId && contractAddress) {
|
|
9006
9207
|
throw new Error('You can only provide either suiObjectId or contractAddress');
|
|
@@ -9258,7 +9459,7 @@ class Transactions extends Base {
|
|
|
9258
9459
|
}
|
|
9259
9460
|
else if (hasShares) {
|
|
9260
9461
|
transferResponse = await this.request(TransactionsRoutes.transferWithShares, {
|
|
9261
|
-
payload: Object.assign(Object.assign({}, signatureMessage), { clientAuthPubKey: deviceAuthPublicKey, encryptedShares: sharesEncryptedWithWallabyPubKey,
|
|
9462
|
+
payload: Object.assign(Object.assign({}, signatureMessage), { clientAuthPubKey: deviceAuthPublicKey, encryptedShares: sharesEncryptedWithWallabyPubKey, originAddress,
|
|
9262
9463
|
recipientAddress,
|
|
9263
9464
|
assetId,
|
|
9264
9465
|
amount, reference: reference || uuid.v4(), memo }),
|
|
@@ -9267,7 +9468,9 @@ class Transactions extends Base {
|
|
|
9267
9468
|
else {
|
|
9268
9469
|
throw new Error('No valid seed option found on this device.');
|
|
9269
9470
|
}
|
|
9270
|
-
if (!transferResponse ||
|
|
9471
|
+
if (!transferResponse ||
|
|
9472
|
+
transferResponse.error ||
|
|
9473
|
+
(typeof transferResponse === 'object' && Object.keys(transferResponse).length === 0)) {
|
|
9271
9474
|
throw new Error(transferResponse === null || transferResponse === void 0 ? void 0 : transferResponse.error);
|
|
9272
9475
|
}
|
|
9273
9476
|
return transferResponse;
|
|
@@ -9469,6 +9672,34 @@ class Wallaby {
|
|
|
9469
9672
|
}
|
|
9470
9673
|
}
|
|
9471
9674
|
|
|
9675
|
+
exports.AndroidVersionNotSupportedError = AndroidVersionNotSupportedError;
|
|
9676
|
+
exports.AuthenticatorGeneralError = AuthenticatorGeneralError;
|
|
9677
|
+
exports.AuthenticatorMissingDiscoverableCredentialSupportError = AuthenticatorMissingDiscoverableCredentialSupportError;
|
|
9678
|
+
exports.AuthenticatorMissingUserVerificationSupportError = AuthenticatorMissingUserVerificationSupportError;
|
|
9679
|
+
exports.AuthenticatorNoSupportedPubKeyCredParamsAlgError = AuthenticatorNoSupportedPubKeyCredParamsAlgError;
|
|
9680
|
+
exports.AuthenticatorNotRegisteredError = AuthenticatorNotRegisteredError;
|
|
9681
|
+
exports.AuthenticatorPreviouslyRegisteredError = AuthenticatorPreviouslyRegisteredError;
|
|
9682
|
+
exports.AutoRegisterUserVerificationFailureError = AutoRegisterUserVerificationFailureError;
|
|
9683
|
+
exports.BadConfiguration = BadConfiguration;
|
|
9684
|
+
exports.CeremonyAbortedError = CeremonyAbortedError;
|
|
9685
|
+
exports.IOSVersionNotSupportedError = IOSVersionNotSupportedError;
|
|
9686
|
+
exports.InterruptedError = InterruptedError;
|
|
9687
|
+
exports.InvalidChallengeError = InvalidChallengeError;
|
|
9688
|
+
exports.InvalidDomainError = InvalidDomainError;
|
|
9689
|
+
exports.InvalidRpIdError = InvalidRpIdError;
|
|
9690
|
+
exports.InvalidStateError = InvalidStateError;
|
|
9691
|
+
exports.InvalidUserIdError = InvalidUserIdError;
|
|
9692
|
+
exports.InvalidUserIdLengthError = InvalidUserIdLengthError;
|
|
9693
|
+
exports.MalformedPubKeyCredParamsError = MalformedPubKeyCredParamsError;
|
|
9694
|
+
exports.NativeError = NativeError;
|
|
9695
|
+
exports.NoCredentialsError = NoCredentialsError;
|
|
9696
|
+
exports.NotAllowedError = NotAllowedError;
|
|
9697
|
+
exports.PasskeyErrorCodes = PasskeyErrorCodes;
|
|
9698
|
+
exports.PassthroughSeeCausePropertyError = PassthroughSeeCausePropertyError;
|
|
9699
|
+
exports.RequestFailedError = RequestFailedError;
|
|
9700
|
+
exports.TimeoutError = TimeoutError;
|
|
9701
|
+
exports.UnknownError = UnknownError;
|
|
9702
|
+
exports.UserCancelledError = UserCancelledError;
|
|
9472
9703
|
exports.Wallaby = Wallaby;
|
|
9473
9704
|
exports.createIdentity = createIdentity;
|
|
9474
9705
|
exports.decryptWithPrivateKey = decryptWithPrivateKey;
|