wallaby-cash 2.0.1-alpha.21 → 2.0.1-alpha.23
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/base.d.ts +11 -5
- package/dist/index.cjs.js +111 -54
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +112 -55
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +112 -55
- package/dist/index.js.map +1 -1
- package/dist/lib/auth/auth.service.d.ts +1 -2
- package/dist/lib/utils/is-jwt-expired.d.ts +2 -0
- package/dist/lib/wallet/wallet.service.d.ts +1 -2
- package/dist/package.json +3 -2
- package/dist/types/auth.d.ts +15 -0
- package/dist/types/base.d.ts +10 -1
- package/dist/types/common.d.ts +8 -0
- package/dist/types/wallet.d.ts +1 -2
- package/package.json +3 -2
package/dist/base.d.ts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import { WallabyConfig, RequestOptions, RequestRoute, WallabyConfigOptions } from './types';
|
|
1
|
+
import { WallabyConfig, RequestOptions, RequestRoute, WallabyConfigOptions, AuthType } from './types';
|
|
2
2
|
import { StorageService } from './lib/utils/storage.service';
|
|
3
3
|
import { LocalStorage } from './types/storage';
|
|
4
4
|
export declare abstract class Base {
|
|
5
5
|
private apiKey;
|
|
6
6
|
private baseUrl;
|
|
7
|
-
private jwt?;
|
|
8
7
|
private clientAuthToken;
|
|
9
|
-
userId: string;
|
|
10
|
-
options?: WallabyConfigOptions;
|
|
8
|
+
protected userId: string;
|
|
9
|
+
protected options?: WallabyConfigOptions;
|
|
10
|
+
protected deviceAuthType: AuthType;
|
|
11
11
|
constructor(config: WallabyConfig);
|
|
12
12
|
/**
|
|
13
13
|
* This library uses `localStorage` as the default storage.
|
|
@@ -20,7 +20,13 @@ export declare abstract class Base {
|
|
|
20
20
|
/**
|
|
21
21
|
* @protected
|
|
22
22
|
*/
|
|
23
|
-
protected get device():
|
|
23
|
+
protected get device(): {
|
|
24
|
+
deviceAuthType: AuthType;
|
|
25
|
+
then<TResult1 = import("./types").DeviceInformation, TResult2 = never>(onfulfilled?: ((value: import("./types").DeviceInformation) => TResult1 | PromiseLike<TResult1>) | null | undefined, onrejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | null | undefined): Promise<TResult1 | TResult2>;
|
|
26
|
+
catch<TResult = never>(onrejected?: ((reason: any) => TResult | PromiseLike<TResult>) | null | undefined): Promise<import("./types").DeviceInformation | TResult>;
|
|
27
|
+
finally(onfinally?: (() => void) | null | undefined): Promise<import("./types").DeviceInformation>;
|
|
28
|
+
[Symbol.toStringTag]: string;
|
|
29
|
+
};
|
|
24
30
|
/**
|
|
25
31
|
* @private
|
|
26
32
|
*/
|
package/dist/index.cjs.js
CHANGED
|
@@ -113,6 +113,11 @@ typeof SuppressedError === "function" ? SuppressedError : function (error, suppr
|
|
|
113
113
|
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
114
114
|
};
|
|
115
115
|
|
|
116
|
+
exports.PasskeyChallengeType = void 0;
|
|
117
|
+
(function (PasskeyChallengeType) {
|
|
118
|
+
PasskeyChallengeType["REGISTRATION"] = "webauthn.create";
|
|
119
|
+
PasskeyChallengeType["AUTHENTICATION"] = "webauthn.get";
|
|
120
|
+
})(exports.PasskeyChallengeType || (exports.PasskeyChallengeType = {}));
|
|
116
121
|
exports.PublicKeyCredentialAlgorithm = void 0;
|
|
117
122
|
(function (PublicKeyCredentialAlgorithm) {
|
|
118
123
|
PublicKeyCredentialAlgorithm[PublicKeyCredentialAlgorithm["RS256"] = -257] = "RS256";
|
|
@@ -234,6 +239,12 @@ exports.WalletOwnershipType = void 0;
|
|
|
234
239
|
WalletOwnershipType["MultiOwner"] = "MULTI_OWNER";
|
|
235
240
|
})(exports.WalletOwnershipType || (exports.WalletOwnershipType = {}));
|
|
236
241
|
|
|
242
|
+
exports.AuthType = void 0;
|
|
243
|
+
(function (AuthType) {
|
|
244
|
+
AuthType["Mfa"] = "mfa";
|
|
245
|
+
AuthType["Passkey"] = "passkey";
|
|
246
|
+
})(exports.AuthType || (exports.AuthType = {}));
|
|
247
|
+
|
|
237
248
|
/** Most react native storage engines are async.
|
|
238
249
|
* Explicitly setting these types will make it compatible with Expo Secure Store and React Native Async
|
|
239
250
|
* Storage and RNSecureStorage for now. See:
|
|
@@ -509,6 +520,8 @@ var isTest = browser$1.env.NODE_ENV === 'test';
|
|
|
509
520
|
var PUBLIC_KEY_CREDENTIAL_TIMEOUT = 60000;
|
|
510
521
|
var DEFAULT_ENTROPY_BYTES$1 = 32;
|
|
511
522
|
var PBKDF2_ITERATIONS = 131072;
|
|
523
|
+
var DEFAULT_PRIMARY_SHARE_INDEX = 0;
|
|
524
|
+
var DEFAULT_BACKUP_SHARE_INDEX = 1;
|
|
512
525
|
/**
|
|
513
526
|
* In the options for a Web Authentication credential registration request, the caller can specify a list of cryptographic algorithm identifiers in the pubKeyCredParams field.
|
|
514
527
|
If left unspecified, Chrome uses the default values of ES256 (-7) and RS256 (-257).
|
|
@@ -4722,13 +4735,13 @@ var StorageService = /** @class */ (function () {
|
|
|
4722
4735
|
this.removeItem("accessToken_".concat(this.userId)),
|
|
4723
4736
|
this.delete(exports.LocalStorageItems.AccessToken),
|
|
4724
4737
|
this.delete(exports.LocalStorageItems.ClientAuthPublicKey),
|
|
4725
|
-
this.delete(
|
|
4738
|
+
// this.delete(LocalStorageItems.ClientAuthToken),
|
|
4739
|
+
this.delete(exports.LocalStorageItems.EncryptedAlgorandSeedPhrase),
|
|
4726
4740
|
this.delete(exports.LocalStorageItems.EncryptedStandardSeedPhrase),
|
|
4727
4741
|
this.delete(exports.LocalStorageItems.EncryptedKeyShares),
|
|
4728
4742
|
this.delete(exports.LocalStorageItems.EncryptedShare),
|
|
4729
4743
|
this.delete(exports.LocalStorageItems.PrimaryDeviceKeyShare),
|
|
4730
4744
|
this.delete(exports.LocalStorageItems.BackupDeviceKeyShare),
|
|
4731
|
-
this.delete(exports.LocalStorageItems.EncryptedAlgorandSeedPhrase),
|
|
4732
4745
|
this.delete(exports.LocalStorageItems.EncryptedDevicePrivateKey),
|
|
4733
4746
|
this.delete(exports.LocalStorageItems.WallabyAuthPubKey),
|
|
4734
4747
|
])];
|
|
@@ -4741,47 +4754,50 @@ var StorageService = /** @class */ (function () {
|
|
|
4741
4754
|
};
|
|
4742
4755
|
StorageService.prototype.loadDeviceInformation = function () {
|
|
4743
4756
|
return __awaiter(this, void 0, void 0, function () {
|
|
4744
|
-
var _a, _b
|
|
4745
|
-
var _e;
|
|
4746
|
-
|
|
4747
|
-
|
|
4757
|
+
var _a, _b;
|
|
4758
|
+
var _c, _d, _e, _f;
|
|
4759
|
+
var _g, _h;
|
|
4760
|
+
return __generator(this, function (_j) {
|
|
4761
|
+
switch (_j.label) {
|
|
4748
4762
|
case 0:
|
|
4749
|
-
|
|
4750
|
-
|
|
4763
|
+
_c = {};
|
|
4764
|
+
_d = {};
|
|
4751
4765
|
return [4 /*yield*/, this.fetch(exports.LocalStorageItems.AccessToken)];
|
|
4752
4766
|
case 1:
|
|
4753
|
-
|
|
4767
|
+
_d.accessToken = _j.sent();
|
|
4754
4768
|
return [4 /*yield*/, this.fetch(exports.LocalStorageItems.ClientAuthToken)];
|
|
4755
4769
|
case 2:
|
|
4756
|
-
|
|
4757
|
-
|
|
4758
|
-
|
|
4770
|
+
_c.authTokens = (_d.clientAuthToken = _j.sent(),
|
|
4771
|
+
_d);
|
|
4772
|
+
_b = (_a = JSON).parse;
|
|
4773
|
+
return [4 /*yield*/, this.fetch(exports.LocalStorageItems.PrimaryDeviceKeyShare)];
|
|
4774
|
+
case 3:
|
|
4775
|
+
_c.deviceKeyShare = _b.apply(_a, [(_g = _j.sent()) !== null && _g !== void 0 ? _g : '']);
|
|
4776
|
+
_e = {
|
|
4759
4777
|
clientUserId: this.userId
|
|
4760
4778
|
};
|
|
4761
4779
|
return [4 /*yield*/, this.fetch(exports.LocalStorageItems.EncryptedStandardSeedPhrase)];
|
|
4762
|
-
case 3:
|
|
4763
|
-
_c.encryptedStandardSeedPhrase = _f.sent();
|
|
4764
|
-
return [4 /*yield*/, this.fetch(exports.LocalStorageItems.EncryptedAlgorandSeedPhrase)];
|
|
4765
4780
|
case 4:
|
|
4766
|
-
|
|
4767
|
-
|
|
4768
|
-
|
|
4769
|
-
|
|
4770
|
-
|
|
4771
|
-
|
|
4781
|
+
_e.encryptedStandardSeedPhrase = _j.sent();
|
|
4782
|
+
return [4 /*yield*/, this.fetch(exports.LocalStorageItems.EncryptedAlgorandSeedPhrase)];
|
|
4783
|
+
case 5:
|
|
4784
|
+
_c.user = (_e.encryptedAlgorandSeedPhrase = _j.sent(),
|
|
4785
|
+
_e.wallabyUserId = undefined,
|
|
4786
|
+
_e);
|
|
4787
|
+
_f = {
|
|
4772
4788
|
// Initially these are undefined, because we don't have the decrypted private key yet, and for that we need the password.
|
|
4773
4789
|
deviceAuthPrivateKey: undefined,
|
|
4774
4790
|
deviceAuthPublicKey: undefined
|
|
4775
4791
|
};
|
|
4776
4792
|
return [4 /*yield*/, this.fetch(exports.LocalStorageItems.EncryptedDevicePrivateKey)];
|
|
4777
|
-
case
|
|
4778
|
-
|
|
4793
|
+
case 6:
|
|
4794
|
+
_f.deviceEncryptedPrivateKey = _j.sent();
|
|
4779
4795
|
return [4 /*yield*/, this.fetch(exports.LocalStorageItems.WallabyAuthPubKey)];
|
|
4780
|
-
case
|
|
4781
|
-
|
|
4796
|
+
case 7: return [2 /*return*/, (_c.credentials = (_f.wallabyPublicKey = _j.sent(),
|
|
4797
|
+
_f),
|
|
4782
4798
|
// hostname: window ? window?.location?.hostname : 'wallaby.cash',
|
|
4783
|
-
|
|
4784
|
-
|
|
4799
|
+
_c.hostname = typeof window === 'undefined' ? 'republic.com' : (_h = window === null || window === void 0 ? void 0 : window.location) === null || _h === void 0 ? void 0 : _h.hostname,
|
|
4800
|
+
_c)];
|
|
4785
4801
|
}
|
|
4786
4802
|
});
|
|
4787
4803
|
});
|
|
@@ -4817,6 +4833,23 @@ function jwtHasExpired(jwt) {
|
|
|
4817
4833
|
}
|
|
4818
4834
|
return millisecondsToJWTTimeout(jwt) <= 0;
|
|
4819
4835
|
}
|
|
4836
|
+
function jwtHasSameUser(jwt, userId) {
|
|
4837
|
+
if (!jwt) {
|
|
4838
|
+
return false;
|
|
4839
|
+
}
|
|
4840
|
+
var jwtDecoded = jwtDecode.jwtDecode(jwt);
|
|
4841
|
+
if (jwtDecoded.externalUserId !== userId) {
|
|
4842
|
+
return false;
|
|
4843
|
+
}
|
|
4844
|
+
return true;
|
|
4845
|
+
}
|
|
4846
|
+
function jwtIsSecure(jwt) {
|
|
4847
|
+
var jwtDecoded = jwtDecode.jwtDecode(jwt);
|
|
4848
|
+
if (!jwtDecoded.mfaVerified) {
|
|
4849
|
+
return false;
|
|
4850
|
+
}
|
|
4851
|
+
return true;
|
|
4852
|
+
}
|
|
4820
4853
|
/**
|
|
4821
4854
|
* Calculates the remaining time in milliseconds until a given JWT expires.
|
|
4822
4855
|
*
|
|
@@ -4839,6 +4872,16 @@ var Base = /** @class */ (function () {
|
|
|
4839
4872
|
this.userId = config.userId;
|
|
4840
4873
|
this.clientAuthToken = (_a = config.clientAuthToken) !== null && _a !== void 0 ? _a : config === null || config === void 0 ? void 0 : config.jwt;
|
|
4841
4874
|
this.options = config.options;
|
|
4875
|
+
this.request = this.request.bind(this);
|
|
4876
|
+
if (!jwtHasSameUser(this.clientAuthToken, this.userId)) {
|
|
4877
|
+
throw new Error('Client auth token does not match the user id. Blocking API call.');
|
|
4878
|
+
}
|
|
4879
|
+
if (!isTest && jwtIsSecure(this.clientAuthToken)) {
|
|
4880
|
+
this.deviceAuthType = exports.AuthType.Passkey;
|
|
4881
|
+
}
|
|
4882
|
+
else {
|
|
4883
|
+
this.deviceAuthType = exports.AuthType.Mfa;
|
|
4884
|
+
}
|
|
4842
4885
|
}
|
|
4843
4886
|
Object.defineProperty(Base.prototype, "deviceStorage", {
|
|
4844
4887
|
/**
|
|
@@ -4866,7 +4909,7 @@ var Base = /** @class */ (function () {
|
|
|
4866
4909
|
* @protected
|
|
4867
4910
|
*/
|
|
4868
4911
|
get: function () {
|
|
4869
|
-
return this.storageService.loadDeviceInformation();
|
|
4912
|
+
return __assign(__assign({}, this.storageService.loadDeviceInformation()), { deviceAuthType: this.deviceAuthType });
|
|
4870
4913
|
},
|
|
4871
4914
|
enumerable: false,
|
|
4872
4915
|
configurable: true
|
|
@@ -4876,13 +4919,13 @@ var Base = /** @class */ (function () {
|
|
|
4876
4919
|
* @private
|
|
4877
4920
|
*/
|
|
4878
4921
|
get: function () {
|
|
4879
|
-
var _a, _b, _c, _d, _e;
|
|
4922
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
4880
4923
|
return {
|
|
4881
4924
|
apiKey: this.apiKey,
|
|
4882
4925
|
baseUrl: this.baseUrl,
|
|
4883
4926
|
environment: (_b = (_a = this.options) === null || _a === void 0 ? void 0 : _a.environment) !== null && _b !== void 0 ? _b : defaultEnvironment,
|
|
4884
4927
|
network: (_d = (_c = this.options) === null || _c === void 0 ? void 0 : _c.network) !== null && _d !== void 0 ? _d : defaultNetwork,
|
|
4885
|
-
hostname: (_e = this.options) === null || _e === void 0 ? void 0 : _e.hostname,
|
|
4928
|
+
hostname: (_f = (_e = this.options) === null || _e === void 0 ? void 0 : _e.hostname) !== null && _f !== void 0 ? _f : (_g = window === null || window === void 0 ? void 0 : window.location) === null || _g === void 0 ? void 0 : _g.hostname,
|
|
4886
4929
|
};
|
|
4887
4930
|
},
|
|
4888
4931
|
enumerable: false,
|
|
@@ -5380,6 +5423,7 @@ var Cipher = /** @class */ (function () {
|
|
|
5380
5423
|
if (typeof cipherText === 'string') {
|
|
5381
5424
|
cipherText = JSON.parse(cipherText);
|
|
5382
5425
|
}
|
|
5426
|
+
console.log('SDK::CipherService::decrypt::cipherText', cipherText);
|
|
5383
5427
|
return [4 /*yield*/, decryptWithPrivateKey(decryptionKey, cipherText)];
|
|
5384
5428
|
case 1:
|
|
5385
5429
|
decrypted = _c.sent();
|
|
@@ -5864,10 +5908,10 @@ var AuthService = /** @class */ (function (_super) {
|
|
|
5864
5908
|
case 1:
|
|
5865
5909
|
signatureMessageResponse = _b.sent();
|
|
5866
5910
|
authentication = void 0;
|
|
5867
|
-
_a =
|
|
5911
|
+
_a = this.deviceAuthType;
|
|
5868
5912
|
switch (_a) {
|
|
5869
|
-
case exports.
|
|
5870
|
-
case exports.
|
|
5913
|
+
case exports.AuthType.Passkey: return [3 /*break*/, 2];
|
|
5914
|
+
case exports.AuthType.Mfa: return [3 /*break*/, 4];
|
|
5871
5915
|
}
|
|
5872
5916
|
return [3 /*break*/, 6];
|
|
5873
5917
|
case 2: return [4 /*yield*/, this.handleSignUpWithPasskey({
|
|
@@ -5909,14 +5953,14 @@ var AuthService = /** @class */ (function (_super) {
|
|
|
5909
5953
|
return __generator(this, function (_b) {
|
|
5910
5954
|
switch (_b.label) {
|
|
5911
5955
|
case 0:
|
|
5912
|
-
_a =
|
|
5956
|
+
_a = this.deviceAuthType;
|
|
5913
5957
|
switch (_a) {
|
|
5914
|
-
case exports.
|
|
5915
|
-
case exports.
|
|
5958
|
+
case exports.AuthType.Passkey: return [3 /*break*/, 1];
|
|
5959
|
+
case exports.AuthType.Mfa: return [3 /*break*/, 3];
|
|
5916
5960
|
}
|
|
5917
5961
|
return [3 /*break*/, 6];
|
|
5918
5962
|
case 1:
|
|
5919
|
-
|
|
5963
|
+
logger.log('SDK::AuthService::signIn::passkey');
|
|
5920
5964
|
return [4 /*yield*/, this.handleSignInWithPasskey({
|
|
5921
5965
|
input: input,
|
|
5922
5966
|
})];
|
|
@@ -6179,7 +6223,7 @@ var AuthService = /** @class */ (function (_super) {
|
|
|
6179
6223
|
_e.label = 10;
|
|
6180
6224
|
case 10: return [4 /*yield*/, this.request(AuthRoutes.signatureMessage, {
|
|
6181
6225
|
method: AuthRoutes.signatureMessage.method,
|
|
6182
|
-
payload: { clientAuthPubKey: devicePublicKey },
|
|
6226
|
+
payload: { clientAuthPubKey: devicePublicKey, },
|
|
6183
6227
|
})];
|
|
6184
6228
|
case 11:
|
|
6185
6229
|
response = _e.sent();
|
|
@@ -6544,7 +6588,7 @@ var AuthService = /** @class */ (function (_super) {
|
|
|
6544
6588
|
clientAuthPubKey: deviceAuthKeys.publicKey,
|
|
6545
6589
|
},
|
|
6546
6590
|
}).then(function (authResponse) { return __awaiter(_this, void 0, void 0, function () {
|
|
6547
|
-
var firstSalt, registrationCredentials, regCred, clientExtensions, authenticationCredentials, authenticationResponse, authenticationExtensions, clientDataJSONDecoded, prfValue, credentialsKeyPair, encryptedDevicePrivKey
|
|
6591
|
+
var firstSalt, registrationCredentials, regCred, clientExtensions, authenticationCredentials, authenticationResponse, authenticationExtensions, clientDataJSONDecoded, prfValue, credentialsKeyPair, encryptedDevicePrivKey;
|
|
6548
6592
|
var _a, _b, _c, _d, _e;
|
|
6549
6593
|
return __generator(this, function (_f) {
|
|
6550
6594
|
switch (_f.label) {
|
|
@@ -6607,8 +6651,6 @@ var AuthService = /** @class */ (function (_super) {
|
|
|
6607
6651
|
})];
|
|
6608
6652
|
case 6:
|
|
6609
6653
|
encryptedDevicePrivKey = _f.sent();
|
|
6610
|
-
passkeyRawId = uint8ArrayToBase64(regCred === null || regCred === void 0 ? void 0 : regCred.rawId);
|
|
6611
|
-
console.log('SDK::AuthService::handlePasskeyRegistration::passkeyRawId', passkeyRawId);
|
|
6612
6654
|
console.log('SDK::AuthService::handlePasskeyRegistration::deviceAuthKeys', deviceAuthKeys);
|
|
6613
6655
|
if (encryptedDevicePrivKey) {
|
|
6614
6656
|
this.storageService.saveInBulk([
|
|
@@ -6638,10 +6680,6 @@ var AuthService = /** @class */ (function (_super) {
|
|
|
6638
6680
|
key: exports.LocalStorageItems.PasskeyCredential,
|
|
6639
6681
|
value: JSON.stringify(regCred),
|
|
6640
6682
|
},
|
|
6641
|
-
{
|
|
6642
|
-
key: exports.LocalStorageItems.PasskeyCredentialId,
|
|
6643
|
-
value: passkeyRawId,
|
|
6644
|
-
},
|
|
6645
6683
|
])];
|
|
6646
6684
|
case 7:
|
|
6647
6685
|
_f.sent();
|
|
@@ -6689,6 +6727,13 @@ var AuthService = /** @class */ (function (_super) {
|
|
|
6689
6727
|
var someChallenge = base64url__default.default.encode(randomSignatureMessage);
|
|
6690
6728
|
var someChallengeBuffer = Uint8Array.from(someChallenge, function (c) { return c.charCodeAt(0); });
|
|
6691
6729
|
return {
|
|
6730
|
+
// allowCredentials: [
|
|
6731
|
+
// {
|
|
6732
|
+
// id: rawId,
|
|
6733
|
+
// type: 'public-key',
|
|
6734
|
+
// transports: ['internal', 'hybrid'],
|
|
6735
|
+
// },
|
|
6736
|
+
// ],
|
|
6692
6737
|
challenge: someChallengeBuffer,
|
|
6693
6738
|
rpId: this.getRelyingPartyId(),
|
|
6694
6739
|
userVerification: skipVerification ? 'discouraged' : 'required',
|
|
@@ -6732,13 +6777,13 @@ var AuthService = /** @class */ (function (_super) {
|
|
|
6732
6777
|
pubKeyCredParams: PUBLIC_KEY_CREDENTIAL_PARAM,
|
|
6733
6778
|
timeout: PUBLIC_KEY_CREDENTIAL_TIMEOUT,
|
|
6734
6779
|
authenticatorSelection: {
|
|
6735
|
-
residentKey: '
|
|
6736
|
-
requireResidentKey:
|
|
6780
|
+
residentKey: 'preferred', // Must be a resident key (discoverable credential)
|
|
6781
|
+
requireResidentKey: false, // Ensures the credential is stored on the authenticator
|
|
6737
6782
|
userVerification: 'required', // for stricter security
|
|
6738
6783
|
// triggering a passkey to save on the same device.
|
|
6739
|
-
authenticatorAttachment: 'platform',
|
|
6784
|
+
// authenticatorAttachment: 'platform' as AuthenticatorAttachment,
|
|
6740
6785
|
// triggering a passkey to save on the browser.
|
|
6741
|
-
|
|
6786
|
+
authenticatorAttachment: 'platform',
|
|
6742
6787
|
},
|
|
6743
6788
|
attestation: 'none',
|
|
6744
6789
|
challenge: utf8ToBytes$2(randomSignatureMessage),
|
|
@@ -7974,18 +8019,17 @@ var WalletService = /** @class */ (function (_super) {
|
|
|
7974
8019
|
* Adds a new device to the wallet by backing up the encrypted share.
|
|
7975
8020
|
*
|
|
7976
8021
|
* @param {string} walletId - The Wallaby wallet ID.
|
|
7977
|
-
* @param {Encrypted}
|
|
8022
|
+
* @param {Encrypted[]} encryptedShares - The array of encrypted backup shares to be processed by Wallaby.
|
|
7978
8023
|
* @param {string} [password] - The password for encrypting the share, if required.
|
|
7979
8024
|
* @param {Uint8Array} [prfValue] - The PRF value used for encryption, if applicable.
|
|
7980
8025
|
* @param {EncryptionMechanism} encryptionMechanism - The mechanism used to encrypt the share.
|
|
7981
8026
|
* @param {AuthenticationResponse} authResponse - The authentication response containing user information.
|
|
7982
|
-
* @param {string} [qrCode] - Optional QR code for session persistence.
|
|
7983
8027
|
*
|
|
7984
8028
|
* @returns {Promise<{ success: boolean; reference: string }>} A promise that resolves with the backup reference.
|
|
7985
8029
|
*/
|
|
7986
8030
|
WalletService.prototype.addNewDevice = function (input) {
|
|
7987
8031
|
return __awaiter(this, void 0, void 0, function () {
|
|
7988
|
-
var encryptedDevicePrivateKey, credentialsKeyPair, decryptedDevicePrivateKey, devicePublicKey, signatureMessage, backUpResponse, error_8;
|
|
8032
|
+
var encryptedDevicePrivateKey, credentialsKeyPair, decryptedDevicePrivateKey, devicePublicKey, signatureMessage, backUpResponse, keyShares, error_8;
|
|
7989
8033
|
var _a;
|
|
7990
8034
|
return __generator(this, function (_b) {
|
|
7991
8035
|
switch (_b.label) {
|
|
@@ -8030,13 +8074,26 @@ var WalletService = /** @class */ (function (_super) {
|
|
|
8030
8074
|
message: signatureMessage.message,
|
|
8031
8075
|
signature: signatureMessage.signature,
|
|
8032
8076
|
clientAuthPubKey: devicePublicKey,
|
|
8033
|
-
|
|
8077
|
+
share: {
|
|
8078
|
+
encrypted: input.encryptedShares[DEFAULT_BACKUP_SHARE_INDEX], // we only want to send the backup share to be rewrapped
|
|
8079
|
+
wrappingPublicKey: input.authResponse.user.wallabyAuthPubKey,
|
|
8080
|
+
type: exports.KeyTypeName.OwnerBackupDeviceShare,
|
|
8081
|
+
},
|
|
8034
8082
|
},
|
|
8035
8083
|
})];
|
|
8036
8084
|
case 6:
|
|
8037
8085
|
backUpResponse = _b.sent();
|
|
8086
|
+
keyShares = [
|
|
8087
|
+
backUpResponse.share, // this is the backup share that is now rewrapped with the new device public key.
|
|
8088
|
+
{
|
|
8089
|
+
encrypted: input.encryptedShares[DEFAULT_PRIMARY_SHARE_INDEX],
|
|
8090
|
+
wrappingPublicKey: input.authResponse.user.wallabyAuthPubKey, // this is the primary share still wrapped from the QR code.
|
|
8091
|
+
type: exports.KeyTypeName.OwnerMainDeviceShare,
|
|
8092
|
+
},
|
|
8093
|
+
];
|
|
8038
8094
|
return [4 /*yield*/, this.handlers.handleKeySharesFromResponse({
|
|
8039
|
-
|
|
8095
|
+
// we pass in both shares to be stored on device.
|
|
8096
|
+
keyShares: keyShares,
|
|
8040
8097
|
devicePrivateKey: decryptedDevicePrivateKey,
|
|
8041
8098
|
credentialsKeyPair: credentialsKeyPair,
|
|
8042
8099
|
})];
|