wallaby-cash 2.3.9 → 3.0.1-alpha.2
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/generated/api.d.ts +85 -111
- package/dist/index.cjs.js +253 -436
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +253 -436
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +253 -436
- package/dist/index.js.map +1 -1
- package/dist/lib/auth/auth.service.d.ts +2 -3
- package/dist/lib/transactions/index.d.ts +2 -3
- package/dist/lib/utils/storage.service.d.ts +0 -12
- package/dist/lib/wallet/wallet-data.service.d.ts +2 -2
- package/dist/lib/wallet/wallet-handlers.service.d.ts +7 -21
- package/dist/lib/wallet/wallet.service.d.ts +7 -18
- package/dist/package.json +13 -6
- package/dist/routes/wallet.d.ts +0 -5
- package/dist/types/auth.d.ts +9 -7
- package/dist/types/storage.d.ts +0 -1
- package/dist/types/transactions.d.ts +7 -4
- package/dist/types/wallet.d.ts +21 -15
- package/package.json +13 -6
- package/dist/lib/auth/auth.model.d.ts +0 -108
- package/dist/lib/transactions/transactions.model.d.ts +0 -22
package/dist/index.cjs.js
CHANGED
|
@@ -4,12 +4,12 @@ Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toString
|
|
|
4
4
|
|
|
5
5
|
const algosdk = require('algosdk');
|
|
6
6
|
const bip39 = require('bip39');
|
|
7
|
+
const uuid = require('uuid');
|
|
7
8
|
const log = require('loglevel');
|
|
8
9
|
const cryptoJs = require('crypto-js');
|
|
9
10
|
const jwtDecode = require('jwt-decode');
|
|
10
11
|
const WebAuthn = require('@simplewebauthn/browser');
|
|
11
12
|
const jsBase64 = require('js-base64');
|
|
12
|
-
const uuid = require('uuid');
|
|
13
13
|
|
|
14
14
|
const _interopDefaultCompat = e => e && typeof e === 'object' && 'default' in e ? e : { default: e };
|
|
15
15
|
|
|
@@ -294,7 +294,6 @@ exports.LocalStorageItems = void 0;
|
|
|
294
294
|
LocalStorageItems["EncryptedAlgorandSeedPhrase"] = "encrypted-algorand-seedPhrase";
|
|
295
295
|
LocalStorageItems["EncryptedDevicePrivateKey"] = "encrypted-private-key";
|
|
296
296
|
LocalStorageItems["ClientAuthPublicKey"] = "client-auth-pub-key";
|
|
297
|
-
LocalStorageItems["WallabyAuthPubKey"] = "wallaby-auth-pub-key";
|
|
298
297
|
LocalStorageItems["ClientAuthToken"] = "republic-jwt";
|
|
299
298
|
LocalStorageItems["PasskeyCredential"] = "pass-key-credential";
|
|
300
299
|
LocalStorageItems["Blob"] = "blob";
|
|
@@ -580,8 +579,6 @@ const defaultNetwork = 'testnet';
|
|
|
580
579
|
const isTest = browser$1.env.NODE_ENV === 'test';
|
|
581
580
|
const DEFAULT_ENTROPY_BYTES$1 = 32;
|
|
582
581
|
const PBKDF2_ITERATIONS = 131072;
|
|
583
|
-
const DEFAULT_PRIMARY_SHARE_INDEX = 0;
|
|
584
|
-
const DEFAULT_BACKUP_SHARE_INDEX = 1;
|
|
585
582
|
const DEFAULT_HOSTNAME = 'https://www.republic.com';
|
|
586
583
|
const MASTER_ENCRYPTION_KEY = '9fa9d3f3c77c20d3a50a08e5299644be29f6e6206ef3479fe75d907fe6db9e4c';
|
|
587
584
|
/**
|
|
@@ -600,7 +597,7 @@ const MASTER_ENCRYPTION_KEY = '9fa9d3f3c77c20d3a50a08e5299644be29f6e6206ef3479fe
|
|
|
600
597
|
{ type: 'public-key', alg: exports.PublicKeyCredentialAlgorithm.ES256 },
|
|
601
598
|
];
|
|
602
599
|
const isWeb = typeof window !== 'undefined' && typeof document !== 'undefined';
|
|
603
|
-
const currentPackageVersion = "
|
|
600
|
+
const currentPackageVersion = "3.0.1-alpha.2" ;
|
|
604
601
|
|
|
605
602
|
/**
|
|
606
603
|
* Storage keys adapter for Storage interface across different platforms.
|
|
@@ -4932,43 +4929,6 @@ class StorageService {
|
|
|
4932
4929
|
}
|
|
4933
4930
|
throw new Error(`Unsupported seed phrase type: ${seedPhraseType}`);
|
|
4934
4931
|
}
|
|
4935
|
-
/**
|
|
4936
|
-
*
|
|
4937
|
-
* Stores Wallaby auth public key to local storage
|
|
4938
|
-
* @param wallabyAuthPubKey
|
|
4939
|
-
*/
|
|
4940
|
-
async setWallabyAuthPubKey(wallabyAuthPubKey) {
|
|
4941
|
-
await this.save(exports.V2KeyNames.WallabyAuthPubKey, wallabyAuthPubKey);
|
|
4942
|
-
}
|
|
4943
|
-
/**
|
|
4944
|
-
*
|
|
4945
|
-
* Fetches Wallaby auth public key from local storage
|
|
4946
|
-
* @returns { string | undefined } Wallaby Auth Public key or undefined.
|
|
4947
|
-
*/
|
|
4948
|
-
async getWallabyAuthPubKey() {
|
|
4949
|
-
let wallabyAuthPubKey = await this.fetch(exports.V2KeyNames.WallabyAuthPubKey);
|
|
4950
|
-
if (wallabyAuthPubKey) {
|
|
4951
|
-
return wallabyAuthPubKey;
|
|
4952
|
-
}
|
|
4953
|
-
// Legacy key migration
|
|
4954
|
-
const legacyKey = `wallabyAuthPubKey_${this.userId}`;
|
|
4955
|
-
const legacyPubKey = await this.getItem(legacyKey);
|
|
4956
|
-
if (legacyPubKey) {
|
|
4957
|
-
wallabyAuthPubKey = legacyPubKey;
|
|
4958
|
-
}
|
|
4959
|
-
else {
|
|
4960
|
-
const v1Key = `${this.environment}-wallaby-auth-public-key-${this.userId}`;
|
|
4961
|
-
const v1PubKey = await this.getItem(v1Key);
|
|
4962
|
-
if (v1PubKey) {
|
|
4963
|
-
wallabyAuthPubKey = v1PubKey;
|
|
4964
|
-
}
|
|
4965
|
-
}
|
|
4966
|
-
if (wallabyAuthPubKey) {
|
|
4967
|
-
await this.setWallabyAuthPubKey(wallabyAuthPubKey);
|
|
4968
|
-
return wallabyAuthPubKey;
|
|
4969
|
-
}
|
|
4970
|
-
return undefined;
|
|
4971
|
-
}
|
|
4972
4932
|
/**
|
|
4973
4933
|
* @deprecated This function is only used in tests, and should not be used anywhere else.
|
|
4974
4934
|
* Encrypts and stores device auth private key
|
|
@@ -5177,7 +5137,15 @@ class StorageService {
|
|
|
5177
5137
|
return undefined;
|
|
5178
5138
|
}
|
|
5179
5139
|
async clearLocalStorage(walletId) {
|
|
5180
|
-
const userKeysToRemove = [
|
|
5140
|
+
const userKeysToRemove = [
|
|
5141
|
+
exports.LocalStorageItems.AccessToken,
|
|
5142
|
+
exports.V2KeyNames.EncryptedDevicePrivateKey,
|
|
5143
|
+
exports.V2KeyNames.WallabyAuthPubKey,
|
|
5144
|
+
exports.V2KeyNames.PasskeyCredential,
|
|
5145
|
+
exports.V2KeyNames.MigrationVersion,
|
|
5146
|
+
exports.V2KeyNames.LastMigratedAt,
|
|
5147
|
+
exports.V2KeyNames.ClientAuthToken,
|
|
5148
|
+
];
|
|
5181
5149
|
await Promise.all(userKeysToRemove.map((key) => this.delete(key)));
|
|
5182
5150
|
if (walletId) {
|
|
5183
5151
|
await Promise.all(this._walletSpecificKeys.map((key) => this.delete(key, { walletId })));
|
|
@@ -6035,16 +6003,6 @@ class Api {
|
|
|
6035
6003
|
* @secure
|
|
6036
6004
|
*/
|
|
6037
6005
|
importWalletSeedPhraseV2: (data, params = {}) => this.http.request(Object.assign({ path: `/api/v1/wallets/create-shares-based-wallet-from-seed`, method: "POST", body: data, secure: true, type: ContentType.Json, format: "json" }, params)),
|
|
6038
|
-
/**
|
|
6039
|
-
* No description
|
|
6040
|
-
*
|
|
6041
|
-
* @tags Wallets, MPC
|
|
6042
|
-
* @name RetrieveShares
|
|
6043
|
-
* @summary Retrieve shares which belong to the user on a specified wallet
|
|
6044
|
-
* @request POST:/api/v1/wallets/retrieve-shares
|
|
6045
|
-
* @secure
|
|
6046
|
-
*/
|
|
6047
|
-
retrieveShares: (data, params = {}) => this.http.request(Object.assign({ path: `/api/v1/wallets/retrieve-shares`, method: "POST", body: data, secure: true, type: ContentType.Json, format: "json" }, params)),
|
|
6048
6006
|
/**
|
|
6049
6007
|
* No description
|
|
6050
6008
|
*
|
|
@@ -6343,16 +6301,6 @@ class Api {
|
|
|
6343
6301
|
* @secure
|
|
6344
6302
|
*/
|
|
6345
6303
|
getEstimateFee: (query, params = {}) => this.http.request(Object.assign({ path: `/api/v1/transactions/estimate-fee`, method: "GET", query: query, secure: true, format: "json" }, params)),
|
|
6346
|
-
/**
|
|
6347
|
-
* No description
|
|
6348
|
-
*
|
|
6349
|
-
* @tags Transactions, Query
|
|
6350
|
-
* @name FetchTransactionByHashOrReference
|
|
6351
|
-
* @summary Fetch transaction status data using a reference or transaction hash
|
|
6352
|
-
* @request GET:/api/v1/transactions/status
|
|
6353
|
-
* @secure
|
|
6354
|
-
*/
|
|
6355
|
-
fetchTransactionByHashOrReference: (query, params = {}) => this.http.request(Object.assign({ path: `/api/v1/transactions/status`, method: "GET", query: query, secure: true, format: "json" }, params)),
|
|
6356
6304
|
/**
|
|
6357
6305
|
* @description The sign and broadcast transaction API was designed and implemented specifically for uses cases where the caller has their own custom raw transaction that is not yet currently supported by Wallaby
|
|
6358
6306
|
*
|
|
@@ -6363,6 +6311,16 @@ class Api {
|
|
|
6363
6311
|
* @secure
|
|
6364
6312
|
*/
|
|
6365
6313
|
signAndBroadcastRawTx: (data, params = {}) => this.http.request(Object.assign({ path: `/api/v1/transactions/sign-broadcast-rawtx`, method: "POST", body: data, secure: true, type: ContentType.Json, format: "json" }, params)),
|
|
6314
|
+
/**
|
|
6315
|
+
* No description
|
|
6316
|
+
*
|
|
6317
|
+
* @tags Transactions, Query
|
|
6318
|
+
* @name FetchTransactionByHashOrReference
|
|
6319
|
+
* @summary Fetch transaction status data using a reference or transaction hash
|
|
6320
|
+
* @request GET:/api/v1/transactions/status
|
|
6321
|
+
* @secure
|
|
6322
|
+
*/
|
|
6323
|
+
fetchTransactionByHashOrReference: (query, params = {}) => this.http.request(Object.assign({ path: `/api/v1/transactions/status`, method: "GET", query: query, secure: true, format: "json" }, params)),
|
|
6366
6324
|
/**
|
|
6367
6325
|
* No description
|
|
6368
6326
|
*
|
|
@@ -7170,11 +7128,6 @@ const WalletRoutes = {
|
|
|
7170
7128
|
method: exports.RequestMethod.Post,
|
|
7171
7129
|
requiresAccessToken: true,
|
|
7172
7130
|
},
|
|
7173
|
-
retrieveShares: {
|
|
7174
|
-
fullPath: '/wallets/retrieve-shares',
|
|
7175
|
-
method: exports.RequestMethod.Post,
|
|
7176
|
-
requiresAccessToken: true,
|
|
7177
|
-
},
|
|
7178
7131
|
create: {
|
|
7179
7132
|
fullPath: '/wallets/create',
|
|
7180
7133
|
method: exports.RequestMethod.Post,
|
|
@@ -7545,7 +7498,7 @@ class PasskeyService {
|
|
|
7545
7498
|
this.authenticator = new Authenticator();
|
|
7546
7499
|
}
|
|
7547
7500
|
preparePasskeyRequestOptions(options) {
|
|
7548
|
-
var _a, _b, _c, _d, _e, _f;
|
|
7501
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
7549
7502
|
const prfExtensionEvaluation = ((_b = (_a = options.extensions) === null || _a === void 0 ? void 0 : _a.prf.eval) === null || _b === void 0 ? void 0 : _b.base64)
|
|
7550
7503
|
? decodeBase64URL(options.extensions.prf.eval.base64)
|
|
7551
7504
|
: ((_d = (_c = options.extensions) === null || _c === void 0 ? void 0 : _c.prf.eval) === null || _d === void 0 ? void 0 : _d.first) instanceof ArrayBuffer
|
|
@@ -7553,11 +7506,13 @@ class PasskeyService {
|
|
|
7553
7506
|
: typeof ((_f = (_e = options.extensions) === null || _e === void 0 ? void 0 : _e.prf.eval) === null || _f === void 0 ? void 0 : _f.first) === 'object'
|
|
7554
7507
|
? new Uint8Array(Object.values(options.extensions.prf.eval.first))
|
|
7555
7508
|
: undefined;
|
|
7556
|
-
const parsedOptions = Object.assign(Object.assign({}, options), { extensions: Object.assign(Object.assign({}, options.extensions), { prf:
|
|
7557
|
-
|
|
7558
|
-
|
|
7559
|
-
|
|
7560
|
-
|
|
7509
|
+
const parsedOptions = Object.assign(Object.assign({}, options), { extensions: Object.assign(Object.assign({}, options.extensions), { prf: prfExtensionEvaluation !== undefined
|
|
7510
|
+
? {
|
|
7511
|
+
eval: {
|
|
7512
|
+
first: prfExtensionEvaluation,
|
|
7513
|
+
},
|
|
7514
|
+
}
|
|
7515
|
+
: ((_h = (_g = options.extensions) === null || _g === void 0 ? void 0 : _g.prf) !== null && _h !== void 0 ? _h : {}) }) });
|
|
7561
7516
|
logger.log('SDK::PasskeyService::preparePasskeyRequestOptions::parsedOptions', !!parsedOptions);
|
|
7562
7517
|
// While the authenticator still works with the prf and would return the response (if any),
|
|
7563
7518
|
// the library `@simplewebauthn/browser` does not support the prf extension in its type intentionally.
|
|
@@ -7565,7 +7520,7 @@ class PasskeyService {
|
|
|
7565
7520
|
return parsedOptions;
|
|
7566
7521
|
}
|
|
7567
7522
|
preparePasskeyCreationOptions(options) {
|
|
7568
|
-
var _a, _b, _c, _d, _e, _f;
|
|
7523
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
7569
7524
|
const prfExtensionEvaluation = ((_b = (_a = options.extensions) === null || _a === void 0 ? void 0 : _a.prf.eval) === null || _b === void 0 ? void 0 : _b.base64)
|
|
7570
7525
|
? decodeBase64URL(options.extensions.prf.eval.base64)
|
|
7571
7526
|
: ((_d = (_c = options.extensions) === null || _c === void 0 ? void 0 : _c.prf.eval) === null || _d === void 0 ? void 0 : _d.first) instanceof ArrayBuffer
|
|
@@ -7573,12 +7528,8 @@ class PasskeyService {
|
|
|
7573
7528
|
: typeof ((_f = (_e = options.extensions) === null || _e === void 0 ? void 0 : _e.prf.eval) === null || _f === void 0 ? void 0 : _f.first) === 'object'
|
|
7574
7529
|
? new Uint8Array(Object.values(options.extensions.prf.eval.first))
|
|
7575
7530
|
: undefined;
|
|
7576
|
-
const parsedOptions = Object.assign(Object.assign({}, options), { extensions: Object.assign(Object.assign({}, options.extensions), { prf: {
|
|
7577
|
-
|
|
7578
|
-
first: prfExtensionEvaluation,
|
|
7579
|
-
},
|
|
7580
|
-
} }) });
|
|
7581
|
-
logger.log('SDK::PasskeyService::preparePasskeyRequestOptions::parsedOptions', !!parsedOptions);
|
|
7531
|
+
const parsedOptions = Object.assign(Object.assign({}, options), { extensions: Object.assign(Object.assign({}, options.extensions), { prf: prfExtensionEvaluation !== undefined ? { eval: { first: prfExtensionEvaluation } } : ((_h = (_g = options.extensions) === null || _g === void 0 ? void 0 : _g.prf) !== null && _h !== void 0 ? _h : {}) }) });
|
|
7532
|
+
logger.log('SDK::PasskeyService::preparePasskeyCreationOptions::parsedOptions', !!parsedOptions);
|
|
7582
7533
|
return parsedOptions;
|
|
7583
7534
|
}
|
|
7584
7535
|
/**
|
|
@@ -7593,7 +7544,10 @@ class PasskeyService {
|
|
|
7593
7544
|
let passkeyCredential;
|
|
7594
7545
|
let signInResponse;
|
|
7595
7546
|
try {
|
|
7596
|
-
const registrationChallengeResponse = await getSignature(
|
|
7547
|
+
const registrationChallengeResponse = await getSignature({
|
|
7548
|
+
deviceAuthKeys: deviceKeyPair,
|
|
7549
|
+
passkeyChallengeType: exports.PasskeyChallengeType.REGISTRATION,
|
|
7550
|
+
});
|
|
7597
7551
|
if (!registrationChallengeResponse.registrationOptions)
|
|
7598
7552
|
throw new WallabyError({
|
|
7599
7553
|
message: 'Passkey challenge could not be retrieved, please try again later.',
|
|
@@ -7636,7 +7590,10 @@ class PasskeyService {
|
|
|
7636
7590
|
catch (error) {
|
|
7637
7591
|
logger.error('SDK::PasskeyService::addNewPasskey::error', error);
|
|
7638
7592
|
if (error && error.code === AuthenticatorPreviouslyRegisteredError.error) {
|
|
7639
|
-
const authenticationChallengeResponse = await getSignature(
|
|
7593
|
+
const authenticationChallengeResponse = await getSignature({
|
|
7594
|
+
deviceAuthKeys: deviceKeyPair,
|
|
7595
|
+
passkeyChallengeType: exports.PasskeyChallengeType.AUTHENTICATION,
|
|
7596
|
+
});
|
|
7640
7597
|
if (!authenticationChallengeResponse.authenticationOptions)
|
|
7641
7598
|
throw new WallabyError({
|
|
7642
7599
|
message: 'Passkey challenge could not be retrieved, please try again later.',
|
|
@@ -7707,9 +7664,10 @@ class PasskeyService {
|
|
|
7707
7664
|
errorCode: exports.ErrorResponseCodes.sdk_passkey_challenge_unavailable,
|
|
7708
7665
|
});
|
|
7709
7666
|
const parsedOptions = this.preparePasskeyRequestOptions(challengeResponse.authenticationOptions);
|
|
7710
|
-
const
|
|
7667
|
+
const prfFirst = (_b = (_a = parsedOptions.extensions.prf) === null || _a === void 0 ? void 0 : _a.eval) === null || _b === void 0 ? void 0 : _b.first;
|
|
7668
|
+
const updatedOptions = Object.assign(Object.assign({}, challengeResponse.authenticationOptions), { extensions: Object.assign(Object.assign({}, omit(parsedOptions.extensions, ['credProps'])), { prf: {
|
|
7711
7669
|
eval: {
|
|
7712
|
-
first:
|
|
7670
|
+
first: prfFirst,
|
|
7713
7671
|
},
|
|
7714
7672
|
} }) });
|
|
7715
7673
|
const passkeyCredential = await this.authenticator.authenticate({
|
|
@@ -7936,10 +7894,6 @@ class PasskeyService {
|
|
|
7936
7894
|
key: exports.LocalStorageItems.AccessToken,
|
|
7937
7895
|
value: authenticationResponse.accessToken,
|
|
7938
7896
|
},
|
|
7939
|
-
{
|
|
7940
|
-
key: exports.LocalStorageItems.WallabyAuthPubKey,
|
|
7941
|
-
value: authenticationResponse.user.wallabyAuthPubKey,
|
|
7942
|
-
},
|
|
7943
7897
|
]);
|
|
7944
7898
|
}
|
|
7945
7899
|
/**
|
|
@@ -8148,13 +8102,15 @@ class AuthService extends Base {
|
|
|
8148
8102
|
* @param { PasskeyChallengeType } passkeyChallengeType the type of passkey challenge to request, either for registration or authentication.
|
|
8149
8103
|
* @returns the messaged, the hash, and the signature using the passed private key.
|
|
8150
8104
|
*/
|
|
8151
|
-
async getSignature(deviceAuthKeys, passkeyChallengeType) {
|
|
8105
|
+
async getSignature({ deviceAuthKeys, walletId, passkeyChallengeType, }) {
|
|
8152
8106
|
try {
|
|
8153
8107
|
logger.debug('SDK::AuthService::getSignature::authType', this.deviceAuthType);
|
|
8154
|
-
const
|
|
8108
|
+
const needsPasskeyChallenge = this.deviceAuthType === exports.AuthType.Passkey;
|
|
8109
|
+
const challengeType = needsPasskeyChallenge ? (passkeyChallengeType !== null && passkeyChallengeType !== void 0 ? passkeyChallengeType : exports.PasskeyChallengeType.REGISTRATION) : undefined;
|
|
8155
8110
|
logger.debug('SDK::AuthService::getSignature::challengeType', challengeType);
|
|
8156
8111
|
const response = await this.request(AuthRoutes.signatureMessage, {
|
|
8157
8112
|
payload: {
|
|
8113
|
+
walletId,
|
|
8158
8114
|
clientAuthPubKey: deviceAuthKeys.publicKey,
|
|
8159
8115
|
passkeyChallengeType: challengeType,
|
|
8160
8116
|
},
|
|
@@ -8185,7 +8141,10 @@ class AuthService extends Base {
|
|
|
8185
8141
|
logger.info('key pair generated', !!deviceKeyPair);
|
|
8186
8142
|
let authentication;
|
|
8187
8143
|
try {
|
|
8188
|
-
const signatureMessageResponse = await this.getSignature(
|
|
8144
|
+
const signatureMessageResponse = await this.getSignature({
|
|
8145
|
+
deviceAuthKeys: deviceKeyPair,
|
|
8146
|
+
passkeyChallengeType: exports.PasskeyChallengeType.REGISTRATION,
|
|
8147
|
+
});
|
|
8189
8148
|
logger.info('signature has been generated', !!signatureMessageResponse);
|
|
8190
8149
|
switch (this.deviceAuthType) {
|
|
8191
8150
|
case exports.AuthType.Passkey:
|
|
@@ -8218,7 +8177,10 @@ class AuthService extends Base {
|
|
|
8218
8177
|
// TODO Add passkey errors to the WallabyError ErrorResponseCodes
|
|
8219
8178
|
if ((error && error.error === InvalidStateError.error) || error.code === AuthenticatorPreviouslyRegisteredError.error) {
|
|
8220
8179
|
logger.info('SDK::AuthService::signUp::handling previously registered passkey error');
|
|
8221
|
-
const newChallenge = await this.getSignature(
|
|
8180
|
+
const newChallenge = await this.getSignature({
|
|
8181
|
+
deviceAuthKeys: deviceKeyPair,
|
|
8182
|
+
passkeyChallengeType: exports.PasskeyChallengeType.AUTHENTICATION,
|
|
8183
|
+
});
|
|
8222
8184
|
authentication = await this.passkeyService.authenticate({
|
|
8223
8185
|
deviceKeyPair: { publicKey: deviceKeyPair.publicKey, decryptedPrivateKey: deviceKeyPair.privateKey },
|
|
8224
8186
|
challengeResponse: newChallenge,
|
|
@@ -8255,10 +8217,7 @@ class AuthService extends Base {
|
|
|
8255
8217
|
errorCode: exports.ErrorResponseCodes.sdk_invalid_parameter,
|
|
8256
8218
|
});
|
|
8257
8219
|
}
|
|
8258
|
-
await this.localStorageService.
|
|
8259
|
-
{ key: exports.LocalStorageItems.AccessToken, value: authentication.accessToken },
|
|
8260
|
-
{ key: exports.LocalStorageItems.WallabyAuthPubKey, value: authentication.user.wallabyAuthPubKey },
|
|
8261
|
-
]);
|
|
8220
|
+
await this.localStorageService.save(exports.LocalStorageItems.AccessToken, authentication.accessToken);
|
|
8262
8221
|
return Object.freeze(Object.assign(Object.assign({}, authentication), input));
|
|
8263
8222
|
}
|
|
8264
8223
|
catch (error) {
|
|
@@ -8334,7 +8293,9 @@ class AuthService extends Base {
|
|
|
8334
8293
|
},
|
|
8335
8294
|
credentialsKeyPair,
|
|
8336
8295
|
});
|
|
8337
|
-
const signatureMessage = await this.getSignature({
|
|
8296
|
+
const signatureMessage = await this.getSignature({
|
|
8297
|
+
deviceAuthKeys: { publicKey: clientPublicKey, privateKey: decryptedClientAuthPrivKey },
|
|
8298
|
+
});
|
|
8338
8299
|
const authentication = await this.request(AuthRoutes.signIn, {
|
|
8339
8300
|
payload: {
|
|
8340
8301
|
externalUserId: this.userId,
|
|
@@ -8458,10 +8419,6 @@ class AuthService extends Base {
|
|
|
8458
8419
|
key: exports.LocalStorageItems.AccessToken,
|
|
8459
8420
|
value: authResponse.accessToken,
|
|
8460
8421
|
},
|
|
8461
|
-
{
|
|
8462
|
-
key: exports.LocalStorageItems.WallabyAuthPubKey,
|
|
8463
|
-
value: authResponse.user.wallabyAuthPubKey,
|
|
8464
|
-
},
|
|
8465
8422
|
]);
|
|
8466
8423
|
return authResponse;
|
|
8467
8424
|
});
|
|
@@ -8546,12 +8503,16 @@ class WalletHandlersService extends Base {
|
|
|
8546
8503
|
this.userId = config.userId;
|
|
8547
8504
|
}
|
|
8548
8505
|
async handleImportWallet(deviceAuthKeys, importWalletInput) {
|
|
8549
|
-
var _a, _b, _c, _d;
|
|
8506
|
+
var _a, _b, _c, _d, _e;
|
|
8550
8507
|
try {
|
|
8551
|
-
|
|
8552
|
-
|
|
8553
|
-
|
|
8554
|
-
|
|
8508
|
+
// Since users importing a wallet can be requesting to create a new record, walletId is not available yet.
|
|
8509
|
+
// However the enclave needs a uuid to bind the ephemeral wallaby auth public key to it for the first request
|
|
8510
|
+
// Using the reference as the fallback for the walletId in this case.
|
|
8511
|
+
const { signature, message, wallabyAuthPubKey } = await this.authService.getSignature({
|
|
8512
|
+
walletId: (_a = importWalletInput.walletId) !== null && _a !== void 0 ? _a : importWalletInput.reference,
|
|
8513
|
+
deviceAuthKeys: { publicKey: deviceAuthKeys.publicKey, privateKey: deviceAuthKeys.privateKey },
|
|
8514
|
+
passkeyChallengeType: this.deviceAuthType === exports.AuthType.Passkey ? exports.PasskeyChallengeType.AUTHENTICATION : undefined,
|
|
8515
|
+
});
|
|
8555
8516
|
if ((importWalletInput.returnWalletOption === exports.ReturnWalletOption.ReturnOnlyEncryptedShares ||
|
|
8556
8517
|
importWalletInput.returnWalletOption === exports.ReturnWalletOption.ReturnBothEncryptedSharesAndSeed) &&
|
|
8557
8518
|
!importWalletInput.keyShareOptions) {
|
|
@@ -8561,7 +8522,7 @@ class WalletHandlersService extends Base {
|
|
|
8561
8522
|
errorCode: exports.ErrorResponseCodes.sdk_missing_parameter,
|
|
8562
8523
|
});
|
|
8563
8524
|
}
|
|
8564
|
-
const { numberOfKeyShares, threshold } = (
|
|
8525
|
+
const { numberOfKeyShares, threshold } = (_b = importWalletInput.keyShareOptions) !== null && _b !== void 0 ? _b : {};
|
|
8565
8526
|
if (threshold && numberOfKeyShares && numberOfKeyShares < threshold) {
|
|
8566
8527
|
throw new WallabyError({
|
|
8567
8528
|
message: 'Number of shares must be greater than or equal to the threshold',
|
|
@@ -8571,10 +8532,10 @@ class WalletHandlersService extends Base {
|
|
|
8571
8532
|
}
|
|
8572
8533
|
const readyForTransportSeedPhrase = await this.cipher.encrypt({
|
|
8573
8534
|
data: importWalletInput.seedPhrase,
|
|
8574
|
-
encryptionKey:
|
|
8535
|
+
encryptionKey: wallabyAuthPubKey,
|
|
8575
8536
|
});
|
|
8576
8537
|
const importWalletPayload = {
|
|
8577
|
-
reference:
|
|
8538
|
+
reference: importWalletInput.reference,
|
|
8578
8539
|
walletId: importWalletInput.walletId,
|
|
8579
8540
|
message,
|
|
8580
8541
|
signature,
|
|
@@ -8584,7 +8545,7 @@ class WalletHandlersService extends Base {
|
|
|
8584
8545
|
numShares: numberOfKeyShares !== null && numberOfKeyShares !== void 0 ? numberOfKeyShares : 0,
|
|
8585
8546
|
threshold: threshold !== null && threshold !== void 0 ? threshold : 0,
|
|
8586
8547
|
walletOwnershipType: exports.WalletOwnershipType.SingleOwner,
|
|
8587
|
-
wallabyKeepsOne: (
|
|
8548
|
+
wallabyKeepsOne: (_d = (_c = importWalletInput.keyShareOptions) === null || _c === void 0 ? void 0 : _c.storeOneKeyShareWithWallaby) !== null && _d !== void 0 ? _d : false,
|
|
8588
8549
|
};
|
|
8589
8550
|
const importWalletRequest = await this.request(WalletRoutes.importSeedPhraseV2, {
|
|
8590
8551
|
payload: importWalletPayload,
|
|
@@ -8609,20 +8570,19 @@ class WalletHandlersService extends Base {
|
|
|
8609
8570
|
credentialsKeyPair,
|
|
8610
8571
|
});
|
|
8611
8572
|
}
|
|
8612
|
-
|
|
8613
|
-
if (importWalletRequest.shares) {
|
|
8573
|
+
if (importWalletRequest.shares && importWalletRequest.encryptedBackupShare) {
|
|
8614
8574
|
await this.handleKeySharesFromResponse({
|
|
8615
8575
|
walletId: importWalletRequest.wallet.id,
|
|
8616
|
-
|
|
8617
|
-
devicePrivateKey: deviceAuthKeys.privateKey,
|
|
8576
|
+
shares: importWalletRequest.shares,
|
|
8618
8577
|
credentialsKeyPair,
|
|
8578
|
+
encryptedBackupShare: importWalletRequest.encryptedBackupShare,
|
|
8619
8579
|
});
|
|
8620
8580
|
}
|
|
8621
8581
|
return Object.assign({}, importWalletRequest);
|
|
8622
8582
|
}
|
|
8623
8583
|
catch (error) {
|
|
8624
8584
|
throw new WallabyError({
|
|
8625
|
-
message: (
|
|
8585
|
+
message: (_e = error.message) !== null && _e !== void 0 ? _e : 'Failed to handle importing the wallet',
|
|
8626
8586
|
statusCode: error.statusCode,
|
|
8627
8587
|
errorCode: error.errorCode,
|
|
8628
8588
|
data: error.data,
|
|
@@ -8644,9 +8604,9 @@ class WalletHandlersService extends Base {
|
|
|
8644
8604
|
var _a, _b, _c, _d, _e, _f;
|
|
8645
8605
|
try {
|
|
8646
8606
|
const { signature, message, hashedMessage } = await this.authService.getSignature({
|
|
8647
|
-
publicKey: deviceAuthKeys.publicKey,
|
|
8648
|
-
|
|
8649
|
-
}
|
|
8607
|
+
deviceAuthKeys: { publicKey: deviceAuthKeys.publicKey, privateKey: deviceAuthKeys.privateKey },
|
|
8608
|
+
passkeyChallengeType: exports.PasskeyChallengeType.AUTHENTICATION,
|
|
8609
|
+
});
|
|
8650
8610
|
if ((walletCreationInput.returnWalletOption === exports.ReturnWalletOption.ReturnOnlyEncryptedShares ||
|
|
8651
8611
|
walletCreationInput.returnWalletOption === exports.ReturnWalletOption.ReturnBothEncryptedSharesAndSeed) &&
|
|
8652
8612
|
!walletCreationInput.keyShareOptions) {
|
|
@@ -8696,13 +8656,12 @@ class WalletHandlersService extends Base {
|
|
|
8696
8656
|
credentialsKeyPair,
|
|
8697
8657
|
});
|
|
8698
8658
|
}
|
|
8699
|
-
|
|
8700
|
-
if (walletCreationResponse.shares) {
|
|
8659
|
+
if (walletCreationResponse.shares && walletCreationResponse.encryptedBackupShare) {
|
|
8701
8660
|
await this.handleKeySharesFromResponse({
|
|
8702
8661
|
walletId: walletCreationResponse.wallet.id,
|
|
8703
|
-
|
|
8704
|
-
devicePrivateKey: deviceAuthKeys.privateKey,
|
|
8662
|
+
shares: walletCreationResponse.shares,
|
|
8705
8663
|
credentialsKeyPair,
|
|
8664
|
+
encryptedBackupShare: walletCreationResponse.encryptedBackupShare,
|
|
8706
8665
|
});
|
|
8707
8666
|
}
|
|
8708
8667
|
return Object.assign(Object.assign({}, walletCreationResponse), { standardSeedPhrase: decryptedSeedPhrase });
|
|
@@ -8718,44 +8677,29 @@ class WalletHandlersService extends Base {
|
|
|
8718
8677
|
});
|
|
8719
8678
|
}
|
|
8720
8679
|
}
|
|
8721
|
-
async handleKeySharesFromResponse({ walletId,
|
|
8680
|
+
async handleKeySharesFromResponse({ walletId, shares, credentialsKeyPair, encryptedBackupShare, }) {
|
|
8722
8681
|
try {
|
|
8723
|
-
const
|
|
8724
|
-
|
|
8725
|
-
|
|
8726
|
-
|
|
8727
|
-
|
|
8728
|
-
|
|
8729
|
-
|
|
8730
|
-
|
|
8731
|
-
|
|
8732
|
-
|
|
8733
|
-
|
|
8734
|
-
|
|
8735
|
-
|
|
8736
|
-
|
|
8737
|
-
|
|
8738
|
-
|
|
8739
|
-
|
|
8740
|
-
|
|
8741
|
-
|
|
8742
|
-
|
|
8743
|
-
|
|
8744
|
-
return keyShare;
|
|
8745
|
-
}
|
|
8746
|
-
catch (error) {
|
|
8747
|
-
logger.error('SDK::handleKeySharesFromResponse::error', error);
|
|
8748
|
-
throw new WallabyError({
|
|
8749
|
-
message: (_a = error.message) !== null && _a !== void 0 ? _a : 'Failed to handle key shares from response',
|
|
8750
|
-
statusCode: 500,
|
|
8751
|
-
errorCode: exports.ErrorResponseCodes.sdk_unknown_error,
|
|
8752
|
-
data: error,
|
|
8753
|
-
cause: error.cause,
|
|
8754
|
-
onError: () => logger.log('Reported the error'),
|
|
8755
|
-
});
|
|
8756
|
-
}
|
|
8757
|
-
}));
|
|
8758
|
-
return encryptedKeyShares;
|
|
8682
|
+
const encryptedWithCredentialsKeyShare = await this.cipher.encrypt({
|
|
8683
|
+
data: JSON.stringify(shares[0].encrypted),
|
|
8684
|
+
encryptionKey: credentialsKeyPair.publicKey,
|
|
8685
|
+
});
|
|
8686
|
+
const encryptedWithCredentialsBackupShare = await this.cipher.encrypt({
|
|
8687
|
+
data: JSON.stringify(encryptedBackupShare),
|
|
8688
|
+
encryptionKey: credentialsKeyPair.publicKey,
|
|
8689
|
+
});
|
|
8690
|
+
await this.localStorageService.saveInBulk([
|
|
8691
|
+
{
|
|
8692
|
+
key: exports.V2KeyNames.PrimaryDeviceKeyShare,
|
|
8693
|
+
value: encryptedWithCredentialsKeyShare,
|
|
8694
|
+
walletId,
|
|
8695
|
+
},
|
|
8696
|
+
{
|
|
8697
|
+
key: exports.V2KeyNames.BackupDeviceKeyShare,
|
|
8698
|
+
value: encryptedWithCredentialsBackupShare,
|
|
8699
|
+
walletId,
|
|
8700
|
+
},
|
|
8701
|
+
]);
|
|
8702
|
+
return [encryptedWithCredentialsKeyShare, encryptedWithCredentialsBackupShare];
|
|
8759
8703
|
}
|
|
8760
8704
|
catch (error) {
|
|
8761
8705
|
logger.error('SDK::handleKeySharesFromResponse::error', error);
|
|
@@ -8823,36 +8767,6 @@ class WalletHandlersService extends Base {
|
|
|
8823
8767
|
});
|
|
8824
8768
|
}
|
|
8825
8769
|
}
|
|
8826
|
-
/**
|
|
8827
|
-
*
|
|
8828
|
-
* @param encryptedKeyShares - Encrypted key shares that are encrypted with the wallabyAuthPublicKey.
|
|
8829
|
-
* @param walletId - The ID of the wallet for which the seed phrase is being constructed.
|
|
8830
|
-
* @param deviceAuthKeys - The device authentication key pair used to sign the request.
|
|
8831
|
-
* @description This function constructs the seed phrase from encrypted key shares.
|
|
8832
|
-
* It retrieves the seed phrase by sending a request to the Wallaby API with the encrypted key shares.
|
|
8833
|
-
* The shares should be encrypted with the wallabyAuthPublicKey before passing them into this function.
|
|
8834
|
-
* @returns The function returns the encrypted seed phrase wrapped with client device public key.
|
|
8835
|
-
*/
|
|
8836
|
-
async handleConstructingSeedPhraseFromShares({ encryptedKeyShares, walletId, deviceAuthKeys, }) {
|
|
8837
|
-
try {
|
|
8838
|
-
const { signature, message } = await this.authService.getSignature(deviceAuthKeys, exports.PasskeyChallengeType.AUTHENTICATION);
|
|
8839
|
-
const retrieveSeedPhraseResponse = await this.request(WalletRoutes.retrieveSeedPhrase, {
|
|
8840
|
-
payload: {
|
|
8841
|
-
walletId: walletId,
|
|
8842
|
-
signature,
|
|
8843
|
-
message,
|
|
8844
|
-
clientAuthPubKey: deviceAuthKeys.publicKey,
|
|
8845
|
-
recoveryPubKey: deviceAuthKeys.publicKey,
|
|
8846
|
-
encryptedShares: encryptedKeyShares,
|
|
8847
|
-
},
|
|
8848
|
-
});
|
|
8849
|
-
return retrieveSeedPhraseResponse.encryptedSeed;
|
|
8850
|
-
}
|
|
8851
|
-
catch (error) {
|
|
8852
|
-
logger.error('SDK::handleConstructingSeedPhraseFromShares::error', error);
|
|
8853
|
-
return Promise.reject(error);
|
|
8854
|
-
}
|
|
8855
|
-
}
|
|
8856
8770
|
}
|
|
8857
8771
|
|
|
8858
8772
|
class WalletService extends Base {
|
|
@@ -8962,7 +8876,6 @@ class WalletService extends Base {
|
|
|
8962
8876
|
*/
|
|
8963
8877
|
async export({ walletId, authenticationOptions, exportOptions }) {
|
|
8964
8878
|
try {
|
|
8965
|
-
const { user: { wallabyAuthPubKey }, } = authenticationOptions;
|
|
8966
8879
|
if (!exportOptions.algorandSeedPhrase && !exportOptions.standardSeedPhrase && !exportOptions.keyShares) {
|
|
8967
8880
|
throw new WallabyError({
|
|
8968
8881
|
message: 'exportOptions must be provided with at least one of the following options: algorandSeedPhrase, standardSeedPhrase, keyShares',
|
|
@@ -9072,10 +8985,20 @@ class WalletService extends Base {
|
|
|
9072
8985
|
});
|
|
9073
8986
|
}
|
|
9074
8987
|
const parsedPrimaryShare = safeJsonParse(encryptedPrimaryDeviceShare);
|
|
8988
|
+
const deviceAuthPublicKey = publicKeyByPrivateKey(decryptedDevicePrivateKey);
|
|
8989
|
+
const deviceAuthKeys = {
|
|
8990
|
+
publicKey: deviceAuthPublicKey,
|
|
8991
|
+
privateKey: decryptedDevicePrivateKey,
|
|
8992
|
+
};
|
|
8993
|
+
const { signature, message, wallabyAuthPubKey: ephemeralWallabyAuthPubKey, } = await this.authService.getSignature({
|
|
8994
|
+
deviceAuthKeys,
|
|
8995
|
+
walletId,
|
|
8996
|
+
passkeyChallengeType: exports.PasskeyChallengeType.AUTHENTICATION,
|
|
8997
|
+
});
|
|
9075
8998
|
const wallabyBoundPrimaryShare = await this.cipher.prepareStoredDataForTransport({
|
|
9076
8999
|
storedEncryptedData: parsedPrimaryShare,
|
|
9077
9000
|
encryptedDevicePrivateKey: parsedDevicePrivateKey,
|
|
9078
|
-
wallabyPublicKey: wallabyAuthPubKey,
|
|
9001
|
+
wallabyPublicKey: ephemeralWallabyAuthPubKey || authenticationOptions.user.wallabyAuthPubKey,
|
|
9079
9002
|
options: {
|
|
9080
9003
|
authType: this.deviceAuthType,
|
|
9081
9004
|
password: authenticationOptions.password,
|
|
@@ -9083,17 +9006,18 @@ class WalletService extends Base {
|
|
|
9083
9006
|
prfValue: authenticationOptions.prfValue,
|
|
9084
9007
|
},
|
|
9085
9008
|
});
|
|
9086
|
-
const
|
|
9087
|
-
|
|
9088
|
-
|
|
9089
|
-
|
|
9090
|
-
|
|
9091
|
-
|
|
9092
|
-
|
|
9009
|
+
const retrieveSeedPhraseResponse = await this.request(WalletRoutes.retrieveSeedPhrase, {
|
|
9010
|
+
payload: {
|
|
9011
|
+
walletId: walletId,
|
|
9012
|
+
signature,
|
|
9013
|
+
message,
|
|
9014
|
+
clientAuthPubKey: deviceAuthKeys.publicKey,
|
|
9015
|
+
recoveryPubKey: deviceAuthKeys.publicKey,
|
|
9016
|
+
encryptedShares: [wallabyBoundPrimaryShare],
|
|
9093
9017
|
},
|
|
9094
9018
|
});
|
|
9095
9019
|
decryptedSeedPhrase = await this.cipher.decrypt({
|
|
9096
|
-
cipherText:
|
|
9020
|
+
cipherText: retrieveSeedPhraseResponse.encryptedSeed,
|
|
9097
9021
|
decryptionKey: decryptedDevicePrivateKey,
|
|
9098
9022
|
});
|
|
9099
9023
|
if (exportOptions.algorandSeedPhrase) {
|
|
@@ -9131,7 +9055,9 @@ class WalletService extends Base {
|
|
|
9131
9055
|
* @returns {ImportWalletResponse} The wallet has been created successfully.
|
|
9132
9056
|
*/
|
|
9133
9057
|
async import(input) {
|
|
9058
|
+
var _a;
|
|
9134
9059
|
try {
|
|
9060
|
+
const requestReference = (_a = input.reference) !== null && _a !== void 0 ? _a : uuid.v4();
|
|
9135
9061
|
const encryptedDevicePrivateKey = await this.localStorageService.fetch(exports.LocalStorageItems.EncryptedDevicePrivateKey);
|
|
9136
9062
|
if (!encryptedDevicePrivateKey) {
|
|
9137
9063
|
throw new WallabyError({
|
|
@@ -9162,7 +9088,7 @@ class WalletService extends Base {
|
|
|
9162
9088
|
const importRequest = await this.handlers.handleImportWallet({
|
|
9163
9089
|
publicKey: clientAuthPubKey,
|
|
9164
9090
|
privateKey: decryptedDevicePrivateKey,
|
|
9165
|
-
}, input);
|
|
9091
|
+
}, Object.assign(Object.assign({}, input), { reference: requestReference }));
|
|
9166
9092
|
return importRequest;
|
|
9167
9093
|
}
|
|
9168
9094
|
catch (error) {
|
|
@@ -9176,11 +9102,14 @@ class WalletService extends Base {
|
|
|
9176
9102
|
*
|
|
9177
9103
|
* @param { RecoverWalletRequest } input - The request object containing the necessary parameters.
|
|
9178
9104
|
* @returns { Promise<RecoverWalletResponse> } The response containing the recovered wallet details.
|
|
9105
|
+
*
|
|
9106
|
+
* @deprecated This function is deprecated and will be removed in the next major release. It only supports seed phrase recovery.
|
|
9107
|
+
* Use `import` instead with the `RETURN_ONLY_ENCRYPTED_SEED_PHRASE` option to maintain the same behavior.
|
|
9179
9108
|
*/
|
|
9180
9109
|
async recover(input) {
|
|
9181
|
-
var _a, _b;
|
|
9182
9110
|
try {
|
|
9183
|
-
const wallabyPublicKey = input.authenticationOptions.
|
|
9111
|
+
const wallabyPublicKey = input.authenticationOptions.signatureMessageResponse.wallabyAuthPubKey ||
|
|
9112
|
+
input.authenticationOptions.user.wallabyAuthPubKey;
|
|
9184
9113
|
const deviceAuthKeyPair = createIdentity();
|
|
9185
9114
|
const credentialsKeyPair = await this.cipher.getCredentialsKeyPair({
|
|
9186
9115
|
authType: this.deviceAuthType,
|
|
@@ -9205,12 +9134,12 @@ class WalletService extends Base {
|
|
|
9205
9134
|
storeSeedPhrase: true,
|
|
9206
9135
|
});
|
|
9207
9136
|
}
|
|
9208
|
-
if (
|
|
9137
|
+
if (recoverWithSeedPhraseResponse.shares && recoverWithSeedPhraseResponse.encryptedBackupShare) {
|
|
9209
9138
|
await this.handlers.handleKeySharesFromResponse({
|
|
9210
9139
|
walletId: recoverWithSeedPhraseResponse.wallet.id,
|
|
9211
|
-
|
|
9212
|
-
devicePrivateKey: deviceAuthKeyPair.privateKey,
|
|
9140
|
+
shares: recoverWithSeedPhraseResponse.shares,
|
|
9213
9141
|
credentialsKeyPair,
|
|
9142
|
+
encryptedBackupShare: recoverWithSeedPhraseResponse.encryptedBackupShare,
|
|
9214
9143
|
});
|
|
9215
9144
|
}
|
|
9216
9145
|
await this.authService.storeDeviceKeyPair({
|
|
@@ -9220,27 +9149,37 @@ class WalletService extends Base {
|
|
|
9220
9149
|
return recoverWithSeedPhraseResponse;
|
|
9221
9150
|
}
|
|
9222
9151
|
else if (input.decryptedShares) {
|
|
9223
|
-
|
|
9224
|
-
const encrypted = await this.cipher.encrypt({
|
|
9225
|
-
data: decryptedShare,
|
|
9226
|
-
encryptionKey: wallabyPublicKey,
|
|
9227
|
-
});
|
|
9228
|
-
return encrypted;
|
|
9229
|
-
}));
|
|
9230
|
-
if (!encryptedShares.length) {
|
|
9152
|
+
if (!input.decryptedShares.length) {
|
|
9231
9153
|
throw new WallabyError({
|
|
9232
9154
|
message: 'Decrypted shares are required',
|
|
9233
9155
|
statusCode: 400,
|
|
9234
9156
|
errorCode: exports.ErrorResponseCodes.sdk_missing_parameter,
|
|
9235
9157
|
});
|
|
9236
9158
|
}
|
|
9237
|
-
const
|
|
9238
|
-
encryptedKeyShares: encryptedShares,
|
|
9159
|
+
const { signature, message, wallabyAuthPubKey: ephemeralWallabyAuthPubKey, } = await this.authService.getSignature({
|
|
9239
9160
|
deviceAuthKeys: deviceAuthKeyPair,
|
|
9240
9161
|
walletId: input.walletId,
|
|
9162
|
+
passkeyChallengeType: exports.PasskeyChallengeType.AUTHENTICATION,
|
|
9163
|
+
});
|
|
9164
|
+
const transportEncryptionKey = ephemeralWallabyAuthPubKey || input.authenticationOptions.user.wallabyAuthPubKey;
|
|
9165
|
+
const encryptedShares = await Promise.all(input.decryptedShares.map(async (decryptedShare) => {
|
|
9166
|
+
return await this.cipher.encrypt({
|
|
9167
|
+
data: decryptedShare,
|
|
9168
|
+
encryptionKey: transportEncryptionKey,
|
|
9169
|
+
});
|
|
9170
|
+
}));
|
|
9171
|
+
const retrieveSeedPhraseResponse = await this.request(WalletRoutes.retrieveSeedPhrase, {
|
|
9172
|
+
payload: {
|
|
9173
|
+
walletId: input.walletId,
|
|
9174
|
+
signature,
|
|
9175
|
+
message,
|
|
9176
|
+
clientAuthPubKey: deviceAuthKeyPair.publicKey,
|
|
9177
|
+
recoveryPubKey: deviceAuthKeyPair.publicKey,
|
|
9178
|
+
encryptedShares,
|
|
9179
|
+
},
|
|
9241
9180
|
});
|
|
9242
9181
|
const wallabyBoundRecoverySeedPhrase = await this.cipher.flipEncryptedData({
|
|
9243
|
-
cipherText: encryptedSeed,
|
|
9182
|
+
cipherText: retrieveSeedPhraseResponse.encryptedSeed,
|
|
9244
9183
|
decryptionKey: deviceAuthKeyPair.privateKey,
|
|
9245
9184
|
encryptionKey: wallabyPublicKey,
|
|
9246
9185
|
});
|
|
@@ -9258,12 +9197,12 @@ class WalletService extends Base {
|
|
|
9258
9197
|
storeSeedPhrase: input.storeSeedPhrase,
|
|
9259
9198
|
});
|
|
9260
9199
|
}
|
|
9261
|
-
if (
|
|
9200
|
+
if (recoverWithSeedPhraseResponse.shares && recoverWithSeedPhraseResponse.encryptedBackupShare) {
|
|
9262
9201
|
await this.handlers.handleKeySharesFromResponse({
|
|
9263
9202
|
walletId: recoverWithSeedPhraseResponse.wallet.id,
|
|
9264
|
-
|
|
9265
|
-
devicePrivateKey: deviceAuthKeyPair.privateKey,
|
|
9203
|
+
shares: recoverWithSeedPhraseResponse.shares,
|
|
9266
9204
|
credentialsKeyPair,
|
|
9205
|
+
encryptedBackupShare: recoverWithSeedPhraseResponse.encryptedBackupShare,
|
|
9267
9206
|
});
|
|
9268
9207
|
}
|
|
9269
9208
|
await this.authService.storeDeviceKeyPair({
|
|
@@ -9285,54 +9224,6 @@ class WalletService extends Base {
|
|
|
9285
9224
|
throw error;
|
|
9286
9225
|
}
|
|
9287
9226
|
}
|
|
9288
|
-
/**
|
|
9289
|
-
* @public
|
|
9290
|
-
* Retrieves the encrypted shares for a specified wallet
|
|
9291
|
-
*
|
|
9292
|
-
* @param {string} walletId - The Wallaby wallet ID.
|
|
9293
|
-
* @param {string} [password] - The password for decrypting the shares, if required.
|
|
9294
|
-
* @param {Uint8Array} [prfValue] - The PRF value used for encryption, if applicable.
|
|
9295
|
-
*
|
|
9296
|
-
* @returns {Promise<EncryptedSharesResponse>} A promise that resolves with the encrypted shares.
|
|
9297
|
-
*/
|
|
9298
|
-
async retrieveShares({ walletId, authenticationOptions, deviceAuthKeys, }) {
|
|
9299
|
-
try {
|
|
9300
|
-
const signatureMessage = await this.authService.getSignature({
|
|
9301
|
-
publicKey: deviceAuthKeys.publicKey,
|
|
9302
|
-
privateKey: deviceAuthKeys.privateKey,
|
|
9303
|
-
});
|
|
9304
|
-
// const response = await this.request<RetrieveSharesData>(WalletRoutes.retrieveShares, {
|
|
9305
|
-
// payload: {
|
|
9306
|
-
// walletId,
|
|
9307
|
-
// signature: signatureMessage.signature,
|
|
9308
|
-
// message: signatureMessage.message,
|
|
9309
|
-
// clientAuthPubKey: deviceAuthKeys.publicKey,
|
|
9310
|
-
// },
|
|
9311
|
-
// });
|
|
9312
|
-
const response = await this.api.wallets.retrieveShares({
|
|
9313
|
-
walletId: walletId,
|
|
9314
|
-
signature: signatureMessage.signature,
|
|
9315
|
-
message: signatureMessage.message,
|
|
9316
|
-
clientAuthPubKey: deviceAuthKeys.publicKey,
|
|
9317
|
-
});
|
|
9318
|
-
const credentialsKeyPair = await this.cipher.getCredentialsKeyPair({
|
|
9319
|
-
authType: this.deviceAuthType,
|
|
9320
|
-
password: authenticationOptions.password,
|
|
9321
|
-
salt: authenticationOptions.user.clientSalt,
|
|
9322
|
-
prfValue: authenticationOptions.prfValue,
|
|
9323
|
-
});
|
|
9324
|
-
return await this.handlers.handleKeySharesFromResponse({
|
|
9325
|
-
walletId: walletId,
|
|
9326
|
-
keyShares: response.shares,
|
|
9327
|
-
devicePrivateKey: deviceAuthKeys.privateKey,
|
|
9328
|
-
credentialsKeyPair,
|
|
9329
|
-
});
|
|
9330
|
-
}
|
|
9331
|
-
catch (error) {
|
|
9332
|
-
logger.error('SDK::Wallet::retrieveShares::error', error);
|
|
9333
|
-
throw error;
|
|
9334
|
-
}
|
|
9335
|
-
}
|
|
9336
9227
|
/**
|
|
9337
9228
|
* @public
|
|
9338
9229
|
* Updates the wallet password.
|
|
@@ -9514,20 +9405,14 @@ class WalletService extends Base {
|
|
|
9514
9405
|
});
|
|
9515
9406
|
}
|
|
9516
9407
|
}
|
|
9517
|
-
const
|
|
9518
|
-
|
|
9519
|
-
});
|
|
9520
|
-
const storedEncryptedBackupShare = await this.localStorageService.fetch(exports.LocalStorageItems.BackupDeviceKeyShare, {
|
|
9521
|
-
walletId,
|
|
9522
|
-
});
|
|
9523
|
-
if (!storedEncryptedPrimaryShare || !storedEncryptedBackupShare) {
|
|
9408
|
+
const storedEncryptedBackupShare = await this.localStorageService.fetch(exports.LocalStorageItems.BackupDeviceKeyShare, { walletId });
|
|
9409
|
+
if (!storedEncryptedBackupShare) {
|
|
9524
9410
|
throw new WallabyError({
|
|
9525
9411
|
message: 'You do not have any additional key shares stored on this device, you cannot add a new device from here.',
|
|
9526
9412
|
statusCode: 404,
|
|
9527
9413
|
errorCode: exports.ErrorResponseCodes.sdk_key_shares_not_found,
|
|
9528
9414
|
});
|
|
9529
9415
|
}
|
|
9530
|
-
const parsedPrimaryShare = safeJsonParse(storedEncryptedPrimaryShare);
|
|
9531
9416
|
const parsedBackupShare = safeJsonParse(storedEncryptedBackupShare);
|
|
9532
9417
|
const credentialsKeyPair = await this.cipher.getCredentialsKeyPair({
|
|
9533
9418
|
authType: this.deviceAuthType,
|
|
@@ -9546,17 +9431,6 @@ class WalletService extends Base {
|
|
|
9546
9431
|
errorCode: exports.ErrorResponseCodes.sdk_private_key_decryption_failed,
|
|
9547
9432
|
});
|
|
9548
9433
|
}
|
|
9549
|
-
const wallabyBoundPrimaryShare = await this.cipher.prepareStoredDataForTransport({
|
|
9550
|
-
storedEncryptedData: parsedPrimaryShare,
|
|
9551
|
-
encryptedDevicePrivateKey: parsedEncryptedDevicePrivateKey,
|
|
9552
|
-
wallabyPublicKey: authenticationOptions.user.wallabyAuthPubKey,
|
|
9553
|
-
options: {
|
|
9554
|
-
authType: this.deviceAuthType,
|
|
9555
|
-
password: authenticationOptions.password,
|
|
9556
|
-
prfValue: authenticationOptions.prfValue,
|
|
9557
|
-
salt: authenticationOptions.user.clientSalt,
|
|
9558
|
-
},
|
|
9559
|
-
});
|
|
9560
9434
|
const decryptedOnceBackupShare = await this.cipher.decrypt({
|
|
9561
9435
|
cipherText: parsedBackupShare,
|
|
9562
9436
|
decryptionKey: credentialsKeyPair.privateKey,
|
|
@@ -9565,7 +9439,7 @@ class WalletService extends Base {
|
|
|
9565
9439
|
return {
|
|
9566
9440
|
walletId,
|
|
9567
9441
|
backupUrl,
|
|
9568
|
-
|
|
9442
|
+
encryptedBackupShare: wallabyBoundBackupShare,
|
|
9569
9443
|
};
|
|
9570
9444
|
}
|
|
9571
9445
|
/**
|
|
@@ -9607,48 +9481,26 @@ class WalletService extends Base {
|
|
|
9607
9481
|
});
|
|
9608
9482
|
}
|
|
9609
9483
|
const devicePublicKey = (_a = (await this.localStorageService.fetch(exports.LocalStorageItems.ClientAuthPublicKey))) !== null && _a !== void 0 ? _a : publicKeyByPrivateKey(decryptedDevicePrivateKey);
|
|
9610
|
-
const
|
|
9611
|
-
publicKey: devicePublicKey,
|
|
9612
|
-
privateKey: decryptedDevicePrivateKey,
|
|
9613
|
-
}, exports.PasskeyChallengeType.REGISTRATION);
|
|
9614
|
-
// const backUpResponse: AddNewDeviceResponse = await this.request(WalletRoutes.addNewDevice, {
|
|
9615
|
-
// payload: {
|
|
9616
|
-
// walletId: input.walletId,
|
|
9617
|
-
// message: signatureMessage.message,
|
|
9618
|
-
// signature: signatureMessage.signature,
|
|
9619
|
-
// clientAuthPubKey: devicePublicKey,
|
|
9620
|
-
// share: {
|
|
9621
|
-
// encrypted: input.encryptedShares[DEFAULT_BACKUP_SHARE_INDEX], // we only want to send the backup share to be rewrapped
|
|
9622
|
-
// wrappingPublicKey: input.authenticationOptions.user.wallabyAuthPubKey,
|
|
9623
|
-
// type: KeyTypeName.OwnerBackupDeviceShare,
|
|
9624
|
-
// },
|
|
9625
|
-
// },
|
|
9626
|
-
// });
|
|
9627
|
-
const backUpResponse = await this.api.wallets.addNewDevice({
|
|
9484
|
+
const newSignature = await this.authService.getSignature({
|
|
9485
|
+
deviceAuthKeys: { privateKey: decryptedDevicePrivateKey, publicKey: devicePublicKey },
|
|
9628
9486
|
walletId: input.walletId,
|
|
9629
|
-
|
|
9630
|
-
signature: signatureMessage.signature,
|
|
9631
|
-
clientAuthPubKey: devicePublicKey,
|
|
9632
|
-
share: {
|
|
9633
|
-
encrypted: input.encryptedShares[DEFAULT_BACKUP_SHARE_INDEX], // we only want to send the backup share to be rewrapped
|
|
9634
|
-
wrappingPublicKey: input.authenticationOptions.user.wallabyAuthPubKey,
|
|
9635
|
-
type: exports.KeyTypeName.OwnerBackupDeviceShare,
|
|
9636
|
-
},
|
|
9487
|
+
passkeyChallengeType: this.deviceAuthType === exports.AuthType.Passkey ? exports.PasskeyChallengeType.AUTHENTICATION : undefined,
|
|
9637
9488
|
});
|
|
9638
|
-
const
|
|
9639
|
-
|
|
9640
|
-
|
|
9641
|
-
|
|
9642
|
-
|
|
9643
|
-
|
|
9489
|
+
const backUpResponse = await this.request(WalletRoutes.addNewDevice, {
|
|
9490
|
+
payload: {
|
|
9491
|
+
walletId: input.walletId,
|
|
9492
|
+
clientAuthPubKey: devicePublicKey,
|
|
9493
|
+
signature: newSignature.signature,
|
|
9494
|
+
message: newSignature.message,
|
|
9495
|
+
wallabyAuthPubKey: newSignature.wallabyAuthPubKey,
|
|
9496
|
+
encryptedBackupShare: input.encryptedBackupShare,
|
|
9644
9497
|
},
|
|
9645
|
-
|
|
9498
|
+
});
|
|
9646
9499
|
await this.handlers.handleKeySharesFromResponse({
|
|
9647
9500
|
walletId: input.walletId,
|
|
9648
|
-
|
|
9649
|
-
keyShares: keyShares,
|
|
9650
|
-
devicePrivateKey: decryptedDevicePrivateKey,
|
|
9501
|
+
shares: [backUpResponse.share],
|
|
9651
9502
|
credentialsKeyPair,
|
|
9503
|
+
encryptedBackupShare: input.encryptedBackupShare,
|
|
9652
9504
|
});
|
|
9653
9505
|
return { success: true, reference: backUpResponse.reference };
|
|
9654
9506
|
}
|
|
@@ -9683,77 +9535,18 @@ class WalletService extends Base {
|
|
|
9683
9535
|
}
|
|
9684
9536
|
}
|
|
9685
9537
|
try {
|
|
9686
|
-
const
|
|
9687
|
-
|
|
9688
|
-
|
|
9689
|
-
let transportSeed = undefined;
|
|
9690
|
-
let transportKeyShare = undefined;
|
|
9691
|
-
if (!devicePrivateKey) {
|
|
9692
|
-
throw new WallabyError({
|
|
9693
|
-
message: 'Missing device private key on this device, please recover your wallet first.',
|
|
9694
|
-
statusCode: 404,
|
|
9695
|
-
errorCode: exports.ErrorResponseCodes.sdk_private_key_not_found,
|
|
9696
|
-
});
|
|
9697
|
-
}
|
|
9698
|
-
const parsedDevicePrivateKey = safeJsonParse(devicePrivateKey);
|
|
9699
|
-
if (storedSeedPhrase) {
|
|
9700
|
-
const parsedStoredSeedPhrase = safeJsonParse(storedSeedPhrase);
|
|
9701
|
-
transportSeed = await this.cipher.prepareStoredDataForTransport({
|
|
9702
|
-
storedEncryptedData: parsedStoredSeedPhrase,
|
|
9703
|
-
encryptedDevicePrivateKey: parsedDevicePrivateKey,
|
|
9704
|
-
wallabyPublicKey: input.authenticationOptions.user.wallabyAuthPubKey,
|
|
9705
|
-
options: {
|
|
9706
|
-
authType: this.deviceAuthType,
|
|
9707
|
-
password: input.authenticationOptions.password,
|
|
9708
|
-
salt: input.authenticationOptions.clientSalt,
|
|
9709
|
-
prfValue: input.authenticationOptions.prfValue,
|
|
9710
|
-
},
|
|
9711
|
-
});
|
|
9712
|
-
}
|
|
9713
|
-
else if (primaryKeyShare) {
|
|
9714
|
-
const parsedPrimaryKeyShare = safeJsonParse(primaryKeyShare);
|
|
9715
|
-
transportKeyShare = await this.cipher.prepareStoredDataForTransport({
|
|
9716
|
-
storedEncryptedData: parsedPrimaryKeyShare,
|
|
9717
|
-
encryptedDevicePrivateKey: parsedDevicePrivateKey,
|
|
9718
|
-
wallabyPublicKey: input.authenticationOptions.user.wallabyAuthPubKey,
|
|
9719
|
-
options: {
|
|
9720
|
-
authType: this.deviceAuthType,
|
|
9721
|
-
password: input.authenticationOptions.password,
|
|
9722
|
-
salt: input.authenticationOptions.clientSalt,
|
|
9723
|
-
prfValue: input.authenticationOptions.prfValue,
|
|
9724
|
-
},
|
|
9725
|
-
});
|
|
9726
|
-
}
|
|
9727
|
-
else {
|
|
9728
|
-
throw new WallabyError({
|
|
9729
|
-
message: 'Missing stored seed phrase or primary key share on this device, please recover your wallet first.',
|
|
9730
|
-
statusCode: 404,
|
|
9731
|
-
errorCode: 'sdk_private_key_not_found',
|
|
9732
|
-
});
|
|
9733
|
-
}
|
|
9734
|
-
const derivedCredentialsKeyPair = await this.cipher.getCredentialsKeyPair({
|
|
9735
|
-
authType: this.deviceAuthType,
|
|
9736
|
-
password: input.authenticationOptions.password,
|
|
9737
|
-
salt: input.authenticationOptions.clientSalt,
|
|
9738
|
-
prfValue: input.authenticationOptions.prfValue,
|
|
9739
|
-
});
|
|
9740
|
-
const decryptedDevicePrivateKey = await this.cipher.decrypt({
|
|
9741
|
-
cipherText: parsedDevicePrivateKey,
|
|
9742
|
-
decryptionKey: derivedCredentialsKeyPair.privateKey,
|
|
9743
|
-
});
|
|
9744
|
-
const devicePublicKey = publicKeyByPrivateKey(decryptedDevicePrivateKey);
|
|
9745
|
-
const { signature, message } = await this.authService.getSignature({
|
|
9746
|
-
privateKey: decryptedDevicePrivateKey,
|
|
9747
|
-
publicKey: devicePublicKey,
|
|
9538
|
+
const walletOperationAuth = await this.prepareWalletOperationAuth({
|
|
9539
|
+
walletId,
|
|
9540
|
+
authenticationOptions: input.authenticationOptions,
|
|
9748
9541
|
});
|
|
9749
9542
|
const response = await this.request(WalletRoutes.generateWalletAddresses, {
|
|
9750
9543
|
payload: {
|
|
9751
9544
|
walletId,
|
|
9752
|
-
|
|
9753
|
-
|
|
9754
|
-
|
|
9755
|
-
encryptedSeed:
|
|
9756
|
-
encryptedShares:
|
|
9545
|
+
message: walletOperationAuth.signatureMessage.message,
|
|
9546
|
+
clientAuthPubKey: walletOperationAuth.deviceAuthPublicKey,
|
|
9547
|
+
signature: walletOperationAuth.signatureMessage.signature,
|
|
9548
|
+
encryptedSeed: walletOperationAuth.readyForTransportSeedPhrase,
|
|
9549
|
+
encryptedShares: walletOperationAuth.sharesEncryptedWithWallabyPubKey,
|
|
9757
9550
|
chainName: input.blockchainName,
|
|
9758
9551
|
},
|
|
9759
9552
|
});
|
|
@@ -9937,8 +9730,8 @@ class WalletService extends Base {
|
|
|
9937
9730
|
// During migration, we need to authenticate but avoid creating conflicting device keypairs
|
|
9938
9731
|
const devicePublicKey = publicKeyByPrivateKey(decryptedPrivateKey);
|
|
9939
9732
|
const signInSignatureMessage = await this.authService.getSignature({
|
|
9940
|
-
publicKey: devicePublicKey,
|
|
9941
|
-
|
|
9733
|
+
deviceAuthKeys: { publicKey: devicePublicKey, privateKey: decryptedPrivateKey },
|
|
9734
|
+
walletId,
|
|
9942
9735
|
});
|
|
9943
9736
|
// this would ensure the stored public key is consistent with wallaby and can authenticate the user.
|
|
9944
9737
|
const authResponse = await this.request(AuthRoutes.signIn, {
|
|
@@ -9964,7 +9757,6 @@ class WalletService extends Base {
|
|
|
9964
9757
|
// Store authentication tokens
|
|
9965
9758
|
await this.localStorageService.saveInBulk([
|
|
9966
9759
|
{ key: exports.LocalStorageItems.AccessToken, value: authResponse.accessToken },
|
|
9967
|
-
{ key: exports.LocalStorageItems.WallabyAuthPubKey, value: authResponse.user.wallabyAuthPubKey },
|
|
9968
9760
|
{ key: exports.V2KeyNames.EncryptedStandardSeedPhrase, value: encryptedV2Seed, walletId },
|
|
9969
9761
|
{ key: exports.V2KeyNames.EncryptedDevicePrivateKey, value: encryptedV2PrivateKey },
|
|
9970
9762
|
]);
|
|
@@ -10027,8 +9819,8 @@ class WalletService extends Base {
|
|
|
10027
9819
|
throw error;
|
|
10028
9820
|
}
|
|
10029
9821
|
}
|
|
10030
|
-
async clearDevice() {
|
|
10031
|
-
await this.localStorageService.clearLocalStorage();
|
|
9822
|
+
async clearDevice({ walletId }) {
|
|
9823
|
+
await this.localStorageService.clearLocalStorage(walletId);
|
|
10032
9824
|
}
|
|
10033
9825
|
/**
|
|
10034
9826
|
* Prepares authentication data and encrypted payload for any request.
|
|
@@ -10065,9 +9857,11 @@ class WalletService extends Base {
|
|
|
10065
9857
|
const deviceAuthPublicKey = publicKeyByPrivateKey(decryptedDevicePrivateKey);
|
|
10066
9858
|
// Get signature message
|
|
10067
9859
|
const signatureMessage = await this.authService.getSignature({
|
|
10068
|
-
publicKey: deviceAuthPublicKey,
|
|
10069
|
-
|
|
10070
|
-
|
|
9860
|
+
deviceAuthKeys: { publicKey: deviceAuthPublicKey, privateKey: decryptedDevicePrivateKey },
|
|
9861
|
+
walletId,
|
|
9862
|
+
passkeyChallengeType: exports.PasskeyChallengeType.AUTHENTICATION,
|
|
9863
|
+
});
|
|
9864
|
+
const wallabyPublicKey = signatureMessage.wallabyAuthPubKey || authenticationOptions.user.wallabyAuthPubKey;
|
|
10071
9865
|
// Prepare encrypted data (seed phrase or key shares)
|
|
10072
9866
|
const sharesEncryptedWithWallabyPubKey = [];
|
|
10073
9867
|
let readyForTransportSeedPhrase = undefined;
|
|
@@ -10087,7 +9881,7 @@ class WalletService extends Base {
|
|
|
10087
9881
|
readyForTransportSeedPhrase = await this.cipher.prepareStoredDataForTransport({
|
|
10088
9882
|
storedEncryptedData: parsedSeedPhrase,
|
|
10089
9883
|
encryptedDevicePrivateKey: JSON.parse(encryptedDevicePrivateKey),
|
|
10090
|
-
wallabyPublicKey
|
|
9884
|
+
wallabyPublicKey,
|
|
10091
9885
|
options: {
|
|
10092
9886
|
authType: this.deviceAuthType,
|
|
10093
9887
|
password,
|
|
@@ -10102,7 +9896,7 @@ class WalletService extends Base {
|
|
|
10102
9896
|
const readyForTransportShare = await this.cipher.prepareStoredDataForTransport({
|
|
10103
9897
|
storedEncryptedData: parsedPrimaryShare,
|
|
10104
9898
|
encryptedDevicePrivateKey: JSON.parse(encryptedDevicePrivateKey),
|
|
10105
|
-
wallabyPublicKey
|
|
9899
|
+
wallabyPublicKey,
|
|
10106
9900
|
options: {
|
|
10107
9901
|
authType: this.deviceAuthType,
|
|
10108
9902
|
password,
|
|
@@ -10267,11 +10061,11 @@ class WalletService extends Base {
|
|
|
10267
10061
|
publicKey: clientPublicKey,
|
|
10268
10062
|
privateKey: decryptedClientAuthPrivKey,
|
|
10269
10063
|
}, {
|
|
10270
|
-
walletId: input.walletId,
|
|
10271
10064
|
authenticationOptions: authentication,
|
|
10272
10065
|
seedPhrase: decryptedSeedPhrase,
|
|
10273
10066
|
storeSeedPhrase: false,
|
|
10274
10067
|
returnWalletOption: exports.ReturnWalletOption.ReturnOnlyEncryptedShares, // always only return the encrypted shares
|
|
10068
|
+
walletId: input.walletId,
|
|
10275
10069
|
keyShareOptions: {
|
|
10276
10070
|
threshold: 2,
|
|
10277
10071
|
numberOfKeyShares: 3,
|
|
@@ -10322,20 +10116,31 @@ class WalletService extends Base {
|
|
|
10322
10116
|
logger.info('SDK::WalletService::convertToPasskey::Seed phrase removed from device storage after conversion to passkey');
|
|
10323
10117
|
}
|
|
10324
10118
|
if (!decryptedSeedPhrase && decryptedPrimaryShare) {
|
|
10119
|
+
const deviceAuthKeys = {
|
|
10120
|
+
publicKey: clientPublicKey,
|
|
10121
|
+
privateKey: decryptedClientAuthPrivKey,
|
|
10122
|
+
};
|
|
10123
|
+
const { signature, message, wallabyAuthPubKey: ephemeralWallabyAuthPubKey, } = await this.authService.getSignature({
|
|
10124
|
+
deviceAuthKeys,
|
|
10125
|
+
walletId: input.walletId,
|
|
10126
|
+
passkeyChallengeType: exports.PasskeyChallengeType.AUTHENTICATION,
|
|
10127
|
+
});
|
|
10325
10128
|
const flippedEncryptedPrimaryShare = await this.cipher.encrypt({
|
|
10326
10129
|
data: decryptedPrimaryShare,
|
|
10327
|
-
encryptionKey: authentication.user.wallabyAuthPubKey,
|
|
10130
|
+
encryptionKey: ephemeralWallabyAuthPubKey || authentication.user.wallabyAuthPubKey,
|
|
10328
10131
|
});
|
|
10329
|
-
const
|
|
10330
|
-
|
|
10331
|
-
|
|
10332
|
-
|
|
10333
|
-
|
|
10334
|
-
|
|
10132
|
+
const retrieveSeedPhraseResponse = await this.request(WalletRoutes.retrieveSeedPhrase, {
|
|
10133
|
+
payload: {
|
|
10134
|
+
walletId: input.walletId,
|
|
10135
|
+
signature,
|
|
10136
|
+
message,
|
|
10137
|
+
clientAuthPubKey: deviceAuthKeys.publicKey,
|
|
10138
|
+
recoveryPubKey: deviceAuthKeys.publicKey,
|
|
10139
|
+
encryptedShares: [flippedEncryptedPrimaryShare],
|
|
10335
10140
|
},
|
|
10336
10141
|
});
|
|
10337
10142
|
decryptedSeedPhrase = await this.cipher.decrypt({
|
|
10338
|
-
cipherText:
|
|
10143
|
+
cipherText: retrieveSeedPhraseResponse.encryptedSeed,
|
|
10339
10144
|
decryptionKey: decryptedClientAuthPrivKey,
|
|
10340
10145
|
});
|
|
10341
10146
|
}
|
|
@@ -10442,7 +10247,7 @@ class WalletDataService extends Base {
|
|
|
10442
10247
|
* Note: Either chainName or tokenStandard must be provided.
|
|
10443
10248
|
* @returns { FetchBalanceData } Returns an array of the requested tokens balances.
|
|
10444
10249
|
*/
|
|
10445
|
-
async getMultiTokenBalances({ walletId, tokensAndAddressesList }) {
|
|
10250
|
+
async getMultiTokenBalances({ walletId, tokensAndAddressesList, }) {
|
|
10446
10251
|
try {
|
|
10447
10252
|
if (!tokensAndAddressesList.length) {
|
|
10448
10253
|
throw new WallabyError({
|
|
@@ -10582,7 +10387,7 @@ class WalletDataService extends Base {
|
|
|
10582
10387
|
*
|
|
10583
10388
|
* @throws {Error} If required parameters are missing or invalid.
|
|
10584
10389
|
*/
|
|
10585
|
-
async addTokenToWallet({ assetConfigId, walletId, userId, config, }) {
|
|
10390
|
+
async addTokenToWallet({ assetConfigId, walletId, userId, config, authenticationOptions, }) {
|
|
10586
10391
|
try {
|
|
10587
10392
|
if (!walletId) {
|
|
10588
10393
|
throw new WallabyError({
|
|
@@ -10598,14 +10403,25 @@ class WalletDataService extends Base {
|
|
|
10598
10403
|
errorCode: exports.ErrorResponseCodes.sdk_missing_parameter,
|
|
10599
10404
|
});
|
|
10600
10405
|
}
|
|
10601
|
-
|
|
10602
|
-
|
|
10603
|
-
|
|
10406
|
+
let authPayload = {};
|
|
10407
|
+
if (authenticationOptions) {
|
|
10408
|
+
const walletOperationAuth = await this.walletService.prepareWalletOperationAuth({
|
|
10604
10409
|
walletId,
|
|
10410
|
+
authenticationOptions,
|
|
10411
|
+
});
|
|
10412
|
+
authPayload = {
|
|
10413
|
+
message: walletOperationAuth.signatureMessage.message,
|
|
10414
|
+
clientAuthPubKey: walletOperationAuth.deviceAuthPublicKey,
|
|
10415
|
+
signature: walletOperationAuth.signatureMessage.signature,
|
|
10416
|
+
encryptedSeed: walletOperationAuth.readyForTransportSeedPhrase,
|
|
10417
|
+
encryptedShares: walletOperationAuth.sharesEncryptedWithWallabyPubKey,
|
|
10418
|
+
};
|
|
10419
|
+
}
|
|
10420
|
+
const response = await this.request(WalletRoutes.addTokenToWallet, {
|
|
10421
|
+
payload: Object.assign({ assetConfigId,
|
|
10422
|
+
walletId,
|
|
10605
10423
|
// backend validates and automatically detects userId when none is provided
|
|
10606
|
-
userId: userId || undefined,
|
|
10607
|
-
config,
|
|
10608
|
-
},
|
|
10424
|
+
userId: userId || undefined, config }, authPayload),
|
|
10609
10425
|
});
|
|
10610
10426
|
return response;
|
|
10611
10427
|
}
|
|
@@ -10651,6 +10467,7 @@ class WalletDataService extends Base {
|
|
|
10651
10467
|
assetConfigId: assetConfigId,
|
|
10652
10468
|
walletId: walletId,
|
|
10653
10469
|
userId: userId,
|
|
10470
|
+
authenticationOptions: input.authenticationOptions,
|
|
10654
10471
|
});
|
|
10655
10472
|
return response;
|
|
10656
10473
|
}
|
|
@@ -11206,9 +11023,11 @@ class Swap extends Base {
|
|
|
11206
11023
|
const deviceAuthPublicKey = publicKeyByPrivateKey(decryptedDevicePrivateKey);
|
|
11207
11024
|
// Get signature message
|
|
11208
11025
|
const signatureMessage = await this.authService.getSignature({
|
|
11209
|
-
publicKey: deviceAuthPublicKey,
|
|
11210
|
-
|
|
11211
|
-
|
|
11026
|
+
deviceAuthKeys: { publicKey: deviceAuthPublicKey, privateKey: decryptedDevicePrivateKey },
|
|
11027
|
+
passkeyChallengeType: this.deviceAuthType === exports.AuthType.Passkey ? exports.PasskeyChallengeType.AUTHENTICATION : undefined,
|
|
11028
|
+
walletId,
|
|
11029
|
+
});
|
|
11030
|
+
const wallabyPublicKey = signatureMessage.wallabyAuthPubKey || authenticationOptions.user.wallabyAuthPubKey;
|
|
11212
11031
|
// Prepare encrypted data (seed phrase or key shares)
|
|
11213
11032
|
const sharesEncryptedWithWallabyPubKey = [];
|
|
11214
11033
|
let readyForTransportSeedPhrase = undefined;
|
|
@@ -11229,7 +11048,7 @@ class Swap extends Base {
|
|
|
11229
11048
|
readyForTransportSeedPhrase = await this.cipher.prepareStoredDataForTransport({
|
|
11230
11049
|
storedEncryptedData: parsedSeedPhrase,
|
|
11231
11050
|
encryptedDevicePrivateKey: JSON.parse(encryptedDevicePrivateKey),
|
|
11232
|
-
wallabyPublicKey
|
|
11051
|
+
wallabyPublicKey,
|
|
11233
11052
|
options: {
|
|
11234
11053
|
authType: this.deviceAuthType,
|
|
11235
11054
|
password,
|
|
@@ -11244,7 +11063,7 @@ class Swap extends Base {
|
|
|
11244
11063
|
const readyForTransportShare = await this.cipher.prepareStoredDataForTransport({
|
|
11245
11064
|
storedEncryptedData: parsedPrimaryShare,
|
|
11246
11065
|
encryptedDevicePrivateKey: JSON.parse(encryptedDevicePrivateKey),
|
|
11247
|
-
wallabyPublicKey
|
|
11066
|
+
wallabyPublicKey,
|
|
11248
11067
|
options: {
|
|
11249
11068
|
authType: this.deviceAuthType,
|
|
11250
11069
|
password,
|
|
@@ -11499,18 +11318,14 @@ class Transactions extends Base {
|
|
|
11499
11318
|
* @param {BlockchainName} blockchain
|
|
11500
11319
|
* @returns {FeeEstimateRequest}
|
|
11501
11320
|
*/
|
|
11502
|
-
async estimateFee({ originAddress, recipientAddress, amount,
|
|
11321
|
+
async estimateFee({ originAddress, recipientAddress, amount, transactionType, token, }) {
|
|
11503
11322
|
try {
|
|
11504
11323
|
const response = await this.request(TransactionsRoutes.estimateFee, {
|
|
11505
|
-
queryParams: {
|
|
11506
|
-
chainName: token.chainName,
|
|
11507
|
-
originAddress,
|
|
11324
|
+
queryParams: Object.assign({ chainName: token.chainName, originAddress,
|
|
11508
11325
|
recipientAddress,
|
|
11509
|
-
amount,
|
|
11510
|
-
assetSymbol: token.symbol,
|
|
11511
|
-
transactionType,
|
|
11326
|
+
amount, assetSymbol: token.symbol, transactionType }, (token.tokenStandard && {
|
|
11512
11327
|
tokenStandard: token.tokenStandard,
|
|
11513
|
-
},
|
|
11328
|
+
})),
|
|
11514
11329
|
});
|
|
11515
11330
|
return response;
|
|
11516
11331
|
}
|
|
@@ -11842,9 +11657,11 @@ class Transactions extends Base {
|
|
|
11842
11657
|
const deviceAuthPublicKey = publicKeyByPrivateKey(decryptedDevicePrivateKey);
|
|
11843
11658
|
// Get signature message
|
|
11844
11659
|
const signatureMessage = await this.authService.getSignature({
|
|
11845
|
-
publicKey: deviceAuthPublicKey,
|
|
11846
|
-
|
|
11847
|
-
|
|
11660
|
+
deviceAuthKeys: { publicKey: deviceAuthPublicKey, privateKey: decryptedDevicePrivateKey },
|
|
11661
|
+
walletId,
|
|
11662
|
+
passkeyChallengeType: this.deviceAuthType === exports.AuthType.Passkey ? exports.PasskeyChallengeType.AUTHENTICATION : undefined,
|
|
11663
|
+
});
|
|
11664
|
+
const wallabyPublicKey = signatureMessage.wallabyAuthPubKey || authenticationOptions.user.wallabyAuthPubKey;
|
|
11848
11665
|
// Prepare encrypted data (seed phrase or key shares)
|
|
11849
11666
|
const sharesEncryptedWithWallabyPubKey = [];
|
|
11850
11667
|
let readyForTransportSeedPhrase = undefined;
|
|
@@ -11865,7 +11682,7 @@ class Transactions extends Base {
|
|
|
11865
11682
|
readyForTransportSeedPhrase = await this.cipher.prepareStoredDataForTransport({
|
|
11866
11683
|
storedEncryptedData: parsedSeedPhrase,
|
|
11867
11684
|
encryptedDevicePrivateKey: JSON.parse(encryptedDevicePrivateKey),
|
|
11868
|
-
wallabyPublicKey
|
|
11685
|
+
wallabyPublicKey,
|
|
11869
11686
|
options: {
|
|
11870
11687
|
authType: this.deviceAuthType,
|
|
11871
11688
|
password,
|
|
@@ -11880,7 +11697,7 @@ class Transactions extends Base {
|
|
|
11880
11697
|
const readyForTransportShare = await this.cipher.prepareStoredDataForTransport({
|
|
11881
11698
|
storedEncryptedData: parsedPrimaryShare,
|
|
11882
11699
|
encryptedDevicePrivateKey: JSON.parse(encryptedDevicePrivateKey),
|
|
11883
|
-
wallabyPublicKey
|
|
11700
|
+
wallabyPublicKey,
|
|
11884
11701
|
options: {
|
|
11885
11702
|
authType: this.deviceAuthType,
|
|
11886
11703
|
password,
|