wallaby-cash 2.3.4 → 2.3.6
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 +34 -142
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +32 -142
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +32 -142
- package/dist/index.js.map +1 -1
- package/dist/lib/wallet/wallet-data.service.d.ts +1 -1
- package/dist/lib/wallet/wallet.service.d.ts +4 -7
- package/dist/package.json +3 -1
- package/dist/routes/swap.d.ts +1 -3
- package/dist/routes/wallet.d.ts +1 -1
- package/dist/types/wallet.d.ts +1 -15
- package/package.json +3 -1
package/dist/index.esm.js
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
|
-
import
|
|
1
|
+
import * as algosdk from 'algosdk';
|
|
2
|
+
import * as bip39 from 'bip39';
|
|
2
3
|
import log from 'loglevel';
|
|
3
4
|
import { AES, enc } from 'crypto-js';
|
|
4
5
|
import { jwtDecode } from 'jwt-decode';
|
|
5
6
|
import { omit } from 'lodash';
|
|
6
7
|
import * as WebAuthn from '@simplewebauthn/browser';
|
|
7
8
|
import { atob, toUint8Array } from 'js-base64';
|
|
9
|
+
import { v4 } from 'uuid';
|
|
8
10
|
|
|
9
11
|
/******************************************************************************
|
|
10
12
|
Copyright (c) Microsoft Corporation.
|
|
@@ -570,7 +572,7 @@ const MASTER_ENCRYPTION_KEY = '9fa9d3f3c77c20d3a50a08e5299644be29f6e6206ef3479fe
|
|
|
570
572
|
{ type: 'public-key', alg: PublicKeyCredentialAlgorithm.ES256 },
|
|
571
573
|
];
|
|
572
574
|
const isWeb = typeof window !== 'undefined' && typeof document !== 'undefined';
|
|
573
|
-
const currentPackageVersion = "2.3.
|
|
575
|
+
const currentPackageVersion = "2.3.6" ;
|
|
574
576
|
|
|
575
577
|
/**
|
|
576
578
|
* Storage keys adapter for Storage interface across different platforms.
|
|
@@ -7166,8 +7168,8 @@ const WalletRoutes = {
|
|
|
7166
7168
|
requiresAccessToken: false,
|
|
7167
7169
|
},
|
|
7168
7170
|
getTokenBalance: {
|
|
7169
|
-
fullPath: ({ address,
|
|
7170
|
-
return (`/query/assets/balance?address=${address}&assetSymbol=${
|
|
7171
|
+
fullPath: ({ address, assetSymbol, chainName, tokenStandard }) => {
|
|
7172
|
+
return (`/query/assets/balance?address=${address}&assetSymbol=${assetSymbol}` +
|
|
7171
7173
|
`${tokenStandard ? `&tokenType=${tokenStandard}` : ''}` +
|
|
7172
7174
|
`${chainName ? `&chainName=${chainName}` : ''}`);
|
|
7173
7175
|
},
|
|
@@ -7353,17 +7355,17 @@ const TransactionsRoutes = {
|
|
|
7353
7355
|
|
|
7354
7356
|
const SwapRoutes = {
|
|
7355
7357
|
getQuote: {
|
|
7356
|
-
fullPath: ({ walletId }) => `/
|
|
7358
|
+
fullPath: ({ walletId }) => `/wallets/${walletId}/swap/quote`,
|
|
7357
7359
|
method: RequestMethod.Post,
|
|
7358
7360
|
requiresAccessToken: true,
|
|
7359
7361
|
},
|
|
7360
7362
|
executeSwap: {
|
|
7361
|
-
fullPath:
|
|
7363
|
+
fullPath: '/wallets/execute-swap',
|
|
7362
7364
|
method: RequestMethod.Post,
|
|
7363
7365
|
requiresAccessToken: true,
|
|
7364
7366
|
},
|
|
7365
7367
|
getSwaps: {
|
|
7366
|
-
fullPath: ({ walletId }) => `/
|
|
7368
|
+
fullPath: ({ walletId }) => `/wallets/${walletId}/swaps`,
|
|
7367
7369
|
method: RequestMethod.Get,
|
|
7368
7370
|
requiresAccessToken: true,
|
|
7369
7371
|
},
|
|
@@ -9015,21 +9017,7 @@ class WalletService extends Base {
|
|
|
9015
9017
|
},
|
|
9016
9018
|
});
|
|
9017
9019
|
if (exportOptions.algorandSeedPhrase) {
|
|
9018
|
-
|
|
9019
|
-
standardSeedPhrase: decryptedSeedPhrase,
|
|
9020
|
-
authenticationOptions,
|
|
9021
|
-
walletId,
|
|
9022
|
-
});
|
|
9023
|
-
decryptedAlgorandSeedPhrase = await this.cipher.displayDataFromServer({
|
|
9024
|
-
encryptedData: algorandSeedPhrase.convertedEncryptedSeed,
|
|
9025
|
-
encryptedDevicePrivateKey: parsedDevicePrivateKey,
|
|
9026
|
-
options: {
|
|
9027
|
-
authType: this.deviceAuthType,
|
|
9028
|
-
password: authenticationOptions.password,
|
|
9029
|
-
salt: authenticationOptions.user.clientSalt,
|
|
9030
|
-
prfValue: authenticationOptions.prfValue,
|
|
9031
|
-
},
|
|
9032
|
-
});
|
|
9020
|
+
decryptedAlgorandSeedPhrase = this.getAlgorandSeedPhrase(decryptedSeedPhrase);
|
|
9033
9021
|
if (!decryptedAlgorandSeedPhrase) {
|
|
9034
9022
|
throw new WallabyError({
|
|
9035
9023
|
message: 'Something went wrong decrypting algorand seed phrase.',
|
|
@@ -9073,21 +9061,7 @@ class WalletService extends Base {
|
|
|
9073
9061
|
decryptionKey: decryptedDevicePrivateKey,
|
|
9074
9062
|
});
|
|
9075
9063
|
if (exportOptions.algorandSeedPhrase) {
|
|
9076
|
-
|
|
9077
|
-
standardSeedPhrase: decryptedSeedPhrase,
|
|
9078
|
-
authenticationOptions,
|
|
9079
|
-
walletId,
|
|
9080
|
-
});
|
|
9081
|
-
decryptedAlgorandSeedPhrase = await this.cipher.displayDataFromServer({
|
|
9082
|
-
encryptedData: algorandSeedPhrase.convertedEncryptedSeed,
|
|
9083
|
-
encryptedDevicePrivateKey: parsedDevicePrivateKey,
|
|
9084
|
-
options: {
|
|
9085
|
-
authType: this.deviceAuthType,
|
|
9086
|
-
password: authenticationOptions.password,
|
|
9087
|
-
salt: authenticationOptions.user.clientSalt,
|
|
9088
|
-
prfValue: authenticationOptions.prfValue,
|
|
9089
|
-
},
|
|
9090
|
-
});
|
|
9064
|
+
decryptedAlgorandSeedPhrase = this.getAlgorandSeedPhrase(decryptedSeedPhrase);
|
|
9091
9065
|
}
|
|
9092
9066
|
}
|
|
9093
9067
|
}
|
|
@@ -9448,109 +9422,23 @@ class WalletService extends Base {
|
|
|
9448
9422
|
*
|
|
9449
9423
|
* @public
|
|
9450
9424
|
* Convert BIP39 Standard seed phrase to Algorand fixed 25 words mnemonic phrase
|
|
9451
|
-
* @param {
|
|
9452
|
-
*
|
|
9453
|
-
* - {string} walletId - The Wallaby wallet ID.
|
|
9454
|
-
* - {AuthenticationResponse} authenticationOptions - The authentication options carried from the authentication request (`signIn` | `signUp`)
|
|
9455
|
-
* @returns {ConvertMnemonicSeedPhraseResponse} The mnemonic seed phrase has been converted successfully.
|
|
9425
|
+
* @param {string} bip39Mnemonic - The decrypted standard seed phrase (bip32 standard 24 words mnemonic) to be transformed.
|
|
9426
|
+
* @returns {string} The Algorand fixed 25 words mnemonic phrase.
|
|
9456
9427
|
*/
|
|
9457
|
-
|
|
9428
|
+
getAlgorandSeedPhrase(bip39Mnemonic) {
|
|
9458
9429
|
try {
|
|
9459
|
-
const
|
|
9460
|
-
const
|
|
9461
|
-
|
|
9462
|
-
|
|
9463
|
-
message: 'Device private key could not be found',
|
|
9464
|
-
statusCode: 404,
|
|
9465
|
-
errorCode: ErrorResponseCodes.sdk_private_key_not_found,
|
|
9466
|
-
});
|
|
9467
|
-
const parsedEncryptedDevicePrivateKey = safeJsonParse(storedEncryptedDevicePrivateKey);
|
|
9468
|
-
if (this.deviceAuthType === AuthType.Password && input.authenticationOptions.password) {
|
|
9469
|
-
try {
|
|
9470
|
-
await this.handleUpdateToV2({
|
|
9471
|
-
password: input.authenticationOptions.password,
|
|
9472
|
-
walletId: input.walletId,
|
|
9473
|
-
});
|
|
9474
|
-
}
|
|
9475
|
-
catch (error) {
|
|
9476
|
-
logger.error('SDK::WalletService::getAlgorandSeedPhrase::handleUpdateToV2::error', error);
|
|
9477
|
-
throw new WallabyError({
|
|
9478
|
-
message: 'Error accessing user wallet on this device. Please ensure the password is correct and try again.',
|
|
9479
|
-
statusCode: 500,
|
|
9480
|
-
errorCode: ErrorResponseCodes.sdk_unknown_error,
|
|
9481
|
-
});
|
|
9482
|
-
}
|
|
9483
|
-
}
|
|
9484
|
-
let wallabyBoundSeedPhrase;
|
|
9485
|
-
if (standardSeedPhrase) {
|
|
9486
|
-
const encryptedSeed = await this.cipher.encrypt({
|
|
9487
|
-
data: standardSeedPhrase,
|
|
9488
|
-
encryptionKey: user.wallabyAuthPubKey,
|
|
9489
|
-
});
|
|
9490
|
-
wallabyBoundSeedPhrase = encryptedSeed;
|
|
9491
|
-
}
|
|
9492
|
-
else {
|
|
9493
|
-
const storedEncryptedStandardSeedPhrase = await this.localStorageService.fetch(LocalStorageItems.EncryptedStandardSeedPhrase, {
|
|
9494
|
-
walletId: input.walletId,
|
|
9495
|
-
});
|
|
9496
|
-
if (!storedEncryptedStandardSeedPhrase) {
|
|
9497
|
-
throw new WallabyError({
|
|
9498
|
-
message: 'Device is missing required information, please import your wallet on this device before proceeding.',
|
|
9499
|
-
statusCode: 404,
|
|
9500
|
-
errorCode: ErrorResponseCodes.sdk_seed_phrase_not_found,
|
|
9501
|
-
});
|
|
9502
|
-
}
|
|
9503
|
-
const parsedEncryptedStandardSeedPhrase = safeJsonParse(storedEncryptedStandardSeedPhrase);
|
|
9504
|
-
wallabyBoundSeedPhrase = await this.cipher.prepareStoredDataForTransport({
|
|
9505
|
-
storedEncryptedData: parsedEncryptedStandardSeedPhrase,
|
|
9506
|
-
encryptedDevicePrivateKey: parsedEncryptedDevicePrivateKey,
|
|
9507
|
-
wallabyPublicKey: user.wallabyAuthPubKey,
|
|
9508
|
-
options: {
|
|
9509
|
-
authType: this.deviceAuthType,
|
|
9510
|
-
password,
|
|
9511
|
-
prfValue,
|
|
9512
|
-
salt: clientSalt,
|
|
9513
|
-
},
|
|
9514
|
-
});
|
|
9515
|
-
}
|
|
9516
|
-
const credentialsKeyPair = await this.cipher.getCredentialsKeyPair({
|
|
9517
|
-
authType: this.deviceAuthType,
|
|
9518
|
-
password,
|
|
9519
|
-
salt: clientSalt,
|
|
9520
|
-
prfValue,
|
|
9521
|
-
});
|
|
9522
|
-
const decryptedDevicePrivateKey = await this.cipher.decrypt({
|
|
9523
|
-
cipherText: parsedEncryptedDevicePrivateKey,
|
|
9524
|
-
decryptionKey: credentialsKeyPair.privateKey,
|
|
9525
|
-
});
|
|
9526
|
-
if (!decryptedDevicePrivateKey) {
|
|
9527
|
-
throw new WallabyError({
|
|
9528
|
-
message: 'Failed to decrypt device private key',
|
|
9529
|
-
statusCode: 500,
|
|
9530
|
-
errorCode: ErrorResponseCodes.sdk_private_key_decryption_failed,
|
|
9531
|
-
});
|
|
9532
|
-
}
|
|
9533
|
-
const clientAuthPubKey = publicKeyByPrivateKey(decryptedDevicePrivateKey);
|
|
9534
|
-
const reference = v4();
|
|
9535
|
-
const signatureMessage = await this.authService.getSignature({
|
|
9536
|
-
publicKey: clientAuthPubKey,
|
|
9537
|
-
privateKey: decryptedDevicePrivateKey,
|
|
9538
|
-
});
|
|
9539
|
-
const { message, signature } = signatureMessage;
|
|
9540
|
-
const response = await this.request(WalletRoutes.convertMnemonicSeedPhrase, {
|
|
9541
|
-
payload: {
|
|
9542
|
-
reference,
|
|
9543
|
-
signature,
|
|
9544
|
-
message,
|
|
9545
|
-
clientAuthPubKey,
|
|
9546
|
-
encryptedSeed: wallabyBoundSeedPhrase,
|
|
9547
|
-
},
|
|
9548
|
-
});
|
|
9549
|
-
return response;
|
|
9430
|
+
const seedBuffer = bip39.mnemonicToSeedSync(bip39Mnemonic);
|
|
9431
|
+
const seed = seedBuffer.slice(0, 32);
|
|
9432
|
+
const convertedSeedPhrase = algosdk.mnemonicFromSeed(seed);
|
|
9433
|
+
return convertedSeedPhrase;
|
|
9550
9434
|
}
|
|
9551
9435
|
catch (error) {
|
|
9552
9436
|
logger.error('SDK::Wallet::getAlgorandSeedPhrase::error', error);
|
|
9553
|
-
throw
|
|
9437
|
+
throw new WallabyError({
|
|
9438
|
+
message: error instanceof Error ? error.message : 'Failed to convert seed phrase to Algorand mnemonic.',
|
|
9439
|
+
statusCode: 500,
|
|
9440
|
+
errorCode: ErrorResponseCodes.sdk_unknown_error,
|
|
9441
|
+
});
|
|
9554
9442
|
}
|
|
9555
9443
|
}
|
|
9556
9444
|
/**
|
|
@@ -10484,9 +10372,9 @@ class WalletDataService extends Base {
|
|
|
10484
10372
|
* @param { BlockchainName } chainName the chain name enum. i.e. 'ETHEREUM', 'BITCOIN'
|
|
10485
10373
|
* @returns { TokenBalance } Balance of the token
|
|
10486
10374
|
*/
|
|
10487
|
-
async getTokenBalance({ address,
|
|
10375
|
+
async getTokenBalance({ address, assetSymbol, tokenStandard, chainName }) {
|
|
10488
10376
|
try {
|
|
10489
|
-
if (!address || !
|
|
10377
|
+
if (!address || !assetSymbol || (!chainName && !tokenStandard)) {
|
|
10490
10378
|
throw new WallabyError({
|
|
10491
10379
|
message: 'Missing required parameters',
|
|
10492
10380
|
statusCode: 400,
|
|
@@ -10494,7 +10382,7 @@ class WalletDataService extends Base {
|
|
|
10494
10382
|
});
|
|
10495
10383
|
}
|
|
10496
10384
|
const response = await this.request(WalletRoutes.getTokenBalance, {
|
|
10497
|
-
payload: { address,
|
|
10385
|
+
payload: { address, assetSymbol, chainName, tokenStandard },
|
|
10498
10386
|
});
|
|
10499
10387
|
return response;
|
|
10500
10388
|
}
|
|
@@ -11169,11 +11057,10 @@ class Swap extends Base {
|
|
|
11169
11057
|
}
|
|
11170
11058
|
const { deviceAuthPublicKey, signatureMessage, readyForTransportSeedPhrase, sharesEncryptedWithWallabyPubKey, hasShares } = await this.prepareSwapAuth(authenticationOptions, walletId);
|
|
11171
11059
|
let swapResponse;
|
|
11172
|
-
// Build path with walletId, but exclude it from request body
|
|
11173
|
-
const routePayload = { walletId };
|
|
11174
11060
|
if (readyForTransportSeedPhrase) {
|
|
11175
|
-
swapResponse = await this.request(Object.assign(Object.assign({}, SwapRoutes.executeSwap), { fullPath: SwapRoutes.executeSwap.fullPath
|
|
11061
|
+
swapResponse = await this.request(Object.assign(Object.assign({}, SwapRoutes.executeSwap), { fullPath: SwapRoutes.executeSwap.fullPath }), {
|
|
11176
11062
|
payload: {
|
|
11063
|
+
walletId,
|
|
11177
11064
|
quoteId,
|
|
11178
11065
|
message: signatureMessage.message,
|
|
11179
11066
|
signature: signatureMessage.signature,
|
|
@@ -11183,8 +11070,9 @@ class Swap extends Base {
|
|
|
11183
11070
|
});
|
|
11184
11071
|
}
|
|
11185
11072
|
else if (hasShares) {
|
|
11186
|
-
swapResponse = await this.request(Object.assign(Object.assign({}, SwapRoutes.executeSwap), { fullPath: SwapRoutes.executeSwap.fullPath
|
|
11073
|
+
swapResponse = await this.request(Object.assign(Object.assign({}, SwapRoutes.executeSwap), { fullPath: SwapRoutes.executeSwap.fullPath }), {
|
|
11187
11074
|
payload: {
|
|
11075
|
+
walletId,
|
|
11188
11076
|
quoteId,
|
|
11189
11077
|
message: signatureMessage.message,
|
|
11190
11078
|
signature: signatureMessage.signature,
|
|
@@ -11672,6 +11560,7 @@ class Transactions extends Base {
|
|
|
11672
11560
|
if (readyForTransportSeedPhrase) {
|
|
11673
11561
|
transferResponse = await this.request(TransactionsRoutes.transfer, {
|
|
11674
11562
|
payload: {
|
|
11563
|
+
walletId,
|
|
11675
11564
|
message: signatureMessage.message,
|
|
11676
11565
|
signature: signatureMessage.signature,
|
|
11677
11566
|
clientAuthPubKey: deviceAuthPublicKey,
|
|
@@ -11689,6 +11578,7 @@ class Transactions extends Base {
|
|
|
11689
11578
|
else if (hasShares) {
|
|
11690
11579
|
transferResponse = await this.request(TransactionsRoutes.transferWithShares, {
|
|
11691
11580
|
payload: {
|
|
11581
|
+
walletId,
|
|
11692
11582
|
message: signatureMessage.message,
|
|
11693
11583
|
signature: signatureMessage.signature,
|
|
11694
11584
|
clientAuthPubKey: deviceAuthPublicKey,
|