wallaby-cash 1.3.2 → 1.3.3
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.d.ts +1 -1
- package/dist/index.esm.js +1 -1
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/index.umd.js +1 -1
- package/dist/index.umd.js.map +1 -1
- package/dist/lib/auth/index.d.ts +15 -9
- package/dist/lib/transactions/index.d.ts +5 -5
- package/dist/lib/utils/index.d.ts +22 -7
- package/dist/lib/utils/utils.d.ts +17 -13
- package/dist/lib/wallet/index.d.ts +19 -9
- package/dist/routes/auth.d.ts +5 -0
- package/dist/routes/transactions.d.ts +8 -1
- package/dist/routes/wallet.d.ts +5 -0
- package/dist/tests/data/user.d.ts +3 -2
- package/dist/types/auth.d.ts +5 -10
- package/dist/types/common.d.ts +4 -0
- package/dist/types/transactions.d.ts +2 -2
- package/dist/types/wallet.d.ts +14 -3
- package/package.json +1 -1
- package/src/index.ts +2 -2
- package/src/lib/auth/index.ts +48 -23
- package/src/lib/transactions/index.ts +7 -7
- package/src/lib/utils/index.ts +67 -14
- package/src/lib/utils/utils.ts +41 -26
- package/src/lib/wallet/index.ts +162 -30
- package/src/routes/auth.ts +5 -0
- package/src/routes/transactions.ts +18 -1
- package/src/routes/wallet.ts +5 -0
- package/src/tests/auth.spec.ts +10 -10
- package/src/tests/data/user.ts +3 -2
- package/src/tests/utils.spec.ts +8 -13
- package/src/tests/wallet.spec.ts +5 -5
- package/src/types/auth.ts +5 -11
- package/src/types/common.ts +5 -0
- package/src/types/transactions.ts +2 -2
- package/src/types/wallet.ts +16 -3
|
@@ -25,10 +25,10 @@ export declare class Transactions extends Base {
|
|
|
25
25
|
* @param {string} assetId
|
|
26
26
|
* @param {string} reference
|
|
27
27
|
* @param {string} memo
|
|
28
|
-
* @param {string}
|
|
28
|
+
* @param {string} password
|
|
29
29
|
* @returns {TransferResponse} Transaction object which contains the transaction hash and status
|
|
30
30
|
*/
|
|
31
|
-
transfer({ originAddress, recipientAddress, amount, assetId, reference, memo,
|
|
31
|
+
transfer({ originAddress, recipientAddress, amount, assetId, reference, memo, password, }: TransferRequest): Promise<TransferResponse | undefined>;
|
|
32
32
|
/**
|
|
33
33
|
*
|
|
34
34
|
* @public
|
|
@@ -41,7 +41,7 @@ export declare class Transactions extends Base {
|
|
|
41
41
|
transactionHash: string;
|
|
42
42
|
reference: string;
|
|
43
43
|
blockchain: BlockchainName;
|
|
44
|
-
|
|
44
|
+
password: string;
|
|
45
45
|
}): Promise<TransactionStatusResponse | undefined>;
|
|
46
46
|
/**
|
|
47
47
|
*
|
|
@@ -63,7 +63,7 @@ export declare class Transactions extends Base {
|
|
|
63
63
|
/**
|
|
64
64
|
*
|
|
65
65
|
* @public
|
|
66
|
-
* @param {string}
|
|
66
|
+
* @param {string} password
|
|
67
67
|
* @param {string} ownerAddress
|
|
68
68
|
* @param {string} spenderAddress
|
|
69
69
|
* @param {string} amount
|
|
@@ -74,7 +74,7 @@ export declare class Transactions extends Base {
|
|
|
74
74
|
* @returns {CreateAllowanceResponse}
|
|
75
75
|
*
|
|
76
76
|
*/
|
|
77
|
-
createAllowance({
|
|
77
|
+
createAllowance({ password, ownerAddress, spenderAddress, amount, assetId, contractAddress, reference, memo, }: CreateAllowanceRequest): Promise<{
|
|
78
78
|
transaction: Transaction;
|
|
79
79
|
} | undefined>;
|
|
80
80
|
}
|
|
@@ -1,17 +1,32 @@
|
|
|
1
1
|
import { UtilsResponse, PasswordValidatorResponse, WallabyConfig, SeedPhraseType, RequestMothod } from '../../types';
|
|
2
2
|
import { Base } from '../../base';
|
|
3
|
-
import { Encrypted } from 'eth-crypto';
|
|
4
3
|
export declare class Utils extends Base {
|
|
5
4
|
setWallabyAuthPubKey: (userId: string, wallabyAuthPubKey: string) => void;
|
|
6
5
|
getWallabyAuthPubKey: (userId: string) => UtilsResponse;
|
|
7
|
-
setEncryptedPrivateKey: (userId: string, privateKey: string,
|
|
6
|
+
setEncryptedPrivateKey: (userId: string, privateKey: string, password: string) => boolean;
|
|
8
7
|
getEncryptedPrivateKey: (userId: string) => UtilsResponse;
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
validatePassword: (userId: string, hashKey: string) => PasswordValidatorResponse;
|
|
8
|
+
getEncryptedSeedPhrase: (userId: string, seedPhraseType: SeedPhraseType) => string | undefined;
|
|
9
|
+
getDecryptedSeedPhrase: (userId: string, password: string, salt: string, seedPhraseType: SeedPhraseType) => Promise<UtilsResponse>;
|
|
10
|
+
validatePassword: (userId: string, password: string) => PasswordValidatorResponse;
|
|
11
|
+
private auth;
|
|
14
12
|
constructor(config: WallabyConfig);
|
|
13
|
+
/**
|
|
14
|
+
*
|
|
15
|
+
* Decrypts user private key
|
|
16
|
+
* @param userId
|
|
17
|
+
* @param password
|
|
18
|
+
* @returns
|
|
19
|
+
*/
|
|
20
|
+
getDecryptedPrivateKey: (userId: string, password: string) => UtilsResponse;
|
|
21
|
+
/**
|
|
22
|
+
*
|
|
23
|
+
* @param {string} userId
|
|
24
|
+
* @param {string} decryptedSeedPhrase
|
|
25
|
+
* @param {SeedPhraseType} seedphraseType
|
|
26
|
+
* @param {string} password
|
|
27
|
+
* @param {string} salt
|
|
28
|
+
*/
|
|
29
|
+
setEncryptedSeedPhrase: (userId: string, clientAuthPubKey: string, decryptedSeedPhrase: string, seedPhraseType: SeedPhraseType, password: string, salt: string) => Promise<boolean>;
|
|
15
30
|
fetchFromEndpoint({ endpoint, method, accessTokenRequired, payload, }: {
|
|
16
31
|
endpoint: string;
|
|
17
32
|
method: RequestMothod;
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { Encrypted } from 'eth-crypto';
|
|
2
1
|
import { UtilsResponse, PasswordValidatorResponse, WallabyError, SeedPhraseType } from '../../types';
|
|
3
2
|
/**
|
|
4
3
|
*
|
|
@@ -19,9 +18,9 @@ export declare const getWallabyAuthPubKey: (userId: string) => UtilsResponse;
|
|
|
19
18
|
* Encrypts and stores user private key
|
|
20
19
|
* @param userId ID of the user (should be a uuid)
|
|
21
20
|
* @param privateKey private key
|
|
22
|
-
* @param
|
|
21
|
+
* @param password password that is used to encrypt the private key
|
|
23
22
|
*/
|
|
24
|
-
export declare const setEncryptedPrivateKey: (userId: string, privateKey: string,
|
|
23
|
+
export declare const setEncryptedPrivateKey: (userId: string, privateKey: string, password: string) => boolean;
|
|
25
24
|
/**
|
|
26
25
|
*
|
|
27
26
|
* Fetches encrypted private key from local storage
|
|
@@ -32,37 +31,42 @@ export declare const getEncryptedPrivateKey: (userId: string) => UtilsResponse;
|
|
|
32
31
|
*
|
|
33
32
|
* Decrypts user private key
|
|
34
33
|
* @param userId
|
|
35
|
-
* @param
|
|
34
|
+
* @param password
|
|
36
35
|
* @returns
|
|
37
36
|
*/
|
|
38
|
-
export declare const getDecryptedPrivateKey: (userId: string,
|
|
37
|
+
export declare const getDecryptedPrivateKey: (userId: string, password: string) => UtilsResponse;
|
|
39
38
|
/**
|
|
40
39
|
*
|
|
41
|
-
* @param userId
|
|
42
|
-
* @param
|
|
40
|
+
* @param {string} userId
|
|
41
|
+
* @param {string} decryptedSeedPhrase
|
|
42
|
+
* @param {SeedPhraseType} seedphraseType
|
|
43
|
+
* @param {string} password
|
|
44
|
+
* @param {string} salt
|
|
43
45
|
*/
|
|
44
|
-
export declare const setEncryptedSeedPhrase: (userId: string, clientAuthPubKey: string, decryptedSeedPhrase: string, seedPhraseType: SeedPhraseType) => Promise<boolean>;
|
|
46
|
+
export declare const setEncryptedSeedPhrase: (userId: string, clientAuthPubKey: string, decryptedSeedPhrase: string, seedPhraseType: SeedPhraseType, password: string, salt: string) => Promise<boolean>;
|
|
45
47
|
/**
|
|
46
48
|
*
|
|
47
49
|
* @param {string} userId The user ID for whome the seedphrase belongs.
|
|
48
50
|
* @param {SeedPhraseType} seedPhraseType Standard or Mnemonic seedphrase
|
|
49
51
|
* @returns {UtilsResponse} It returns the encrypted seedphrase as a string or undefined
|
|
50
52
|
*/
|
|
51
|
-
export declare const getEncryptedSeedPhrase: (userId: string, seedPhraseType: SeedPhraseType) =>
|
|
53
|
+
export declare const getEncryptedSeedPhrase: (userId: string, seedPhraseType: SeedPhraseType) => string | undefined;
|
|
52
54
|
/**
|
|
53
55
|
*
|
|
54
56
|
* @param {string} userId
|
|
55
|
-
* @param {string}
|
|
57
|
+
* @param {string} password
|
|
58
|
+
* @param {string} salt
|
|
59
|
+
* @param {SeedPhraseType} seedPhraseType
|
|
56
60
|
* @returns {UtilsResponse} It returns the decrypted seedphrase as a string or undefined
|
|
57
61
|
*/
|
|
58
|
-
export declare const getDecryptedSeedPhrase: (userId: string,
|
|
62
|
+
export declare const getDecryptedSeedPhrase: (userId: string, password: string, salt: string, seedPhraseType: SeedPhraseType) => Promise<UtilsResponse>;
|
|
59
63
|
export declare const setAccessToken: (userId: string, accessToken: string) => boolean;
|
|
60
64
|
export declare const getAccessToken: (userId: string) => UtilsResponse | WallabyError;
|
|
61
65
|
/**
|
|
62
66
|
*
|
|
63
67
|
* @param userId
|
|
64
|
-
* @param
|
|
68
|
+
* @param password
|
|
65
69
|
* @returns
|
|
66
70
|
*/
|
|
67
|
-
export declare const validatePassword: (userId: string,
|
|
71
|
+
export declare const validatePassword: (userId: string, password: string) => PasswordValidatorResponse;
|
|
68
72
|
export declare const clearLocalStorage: (userId: string) => void;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Base } from '../../base';
|
|
2
|
-
import { QueryUserRequest, CreateWalletRequest, CreateWalletResponse, RecoverWalletRequest, RecoverWalletResponse, TokenBalanceRequest, TokenBalancResponse, WallabyError, QueryWalletRequest, UserAssetsResponse, UserWalletsResponse, WalletAssetsResponse, WallabyConfig, ConvertMnemonicSeedPhraseRequest, ConvertMnemonicSeedPhraseResponse, CreateMultisigAssetRequest, CreateMultisigAssetResponse, ClearWalletInput } from '../../types';
|
|
2
|
+
import { QueryUserRequest, CreateWalletRequest, CreateWalletResponse, RecoverWalletRequest, RecoverWalletResponse, TokenBalanceRequest, TokenBalancResponse, WallabyError, QueryWalletRequest, UserAssetsResponse, UserWalletsResponse, WalletAssetsResponse, WallabyConfig, ConvertMnemonicSeedPhraseRequest, ConvertMnemonicSeedPhraseResponse, CreateMultisigAssetRequest, CreateMultisigAssetResponse, ClearWalletInput, ImportWalletRequest, ImportWalletResponse } from '../../types';
|
|
3
3
|
export declare class Wallet extends Base {
|
|
4
4
|
private auth;
|
|
5
5
|
constructor(config: WallabyConfig);
|
|
@@ -20,10 +20,10 @@ export declare class Wallet extends Base {
|
|
|
20
20
|
* @param {string} firstName The user's first name
|
|
21
21
|
* @param {string} lastName The user's last name
|
|
22
22
|
* @param {email} email The user's email
|
|
23
|
-
* @param {string}
|
|
23
|
+
* @param {string} password The user's chosen password
|
|
24
24
|
* @returns {CreateWalletResponse} The wallet has been created successfully
|
|
25
25
|
*/
|
|
26
|
-
create({ firstName, lastName, email,
|
|
26
|
+
create({ firstName, lastName, email, password, }: Pick<CreateWalletRequest, 'firstName' | 'lastName' | 'email' | 'password'>): Promise<CreateWalletResponse | WallabyError>;
|
|
27
27
|
/**
|
|
28
28
|
*
|
|
29
29
|
* @public
|
|
@@ -31,10 +31,20 @@ export declare class Wallet extends Base {
|
|
|
31
31
|
* @param {string} firstName The user's first name
|
|
32
32
|
* @param {string} lastName The user's last name
|
|
33
33
|
* @param {email} email The user's email
|
|
34
|
-
* @param {string}
|
|
34
|
+
* @param {string} password The user's chosen password
|
|
35
35
|
* @returns {CreateWalletResponse} The wallet has been created successfully
|
|
36
36
|
*/
|
|
37
|
-
createWithNewAccount({ firstName, lastName, email,
|
|
37
|
+
createWithNewAccount({ firstName, lastName, email, password, }: Pick<CreateWalletRequest, 'firstName' | 'lastName' | 'email' | 'password'>): Promise<CreateWalletResponse | WallabyError>;
|
|
38
|
+
/**
|
|
39
|
+
*
|
|
40
|
+
* @public
|
|
41
|
+
* @description Import an existing wallet, returns asset list and encrypted seedPhrase
|
|
42
|
+
* @param {string} password The user's chosen password
|
|
43
|
+
* @param {string} seedPhrase The user's seed phrase
|
|
44
|
+
* @returns {ImportWalletResponse} The wallet has been imported successfully
|
|
45
|
+
* The return includes the wallet, wallet assets, and the encrypted seedphrase
|
|
46
|
+
*/
|
|
47
|
+
import({ password, seedPhrase }: ImportWalletRequest): Promise<ImportWalletResponse>;
|
|
38
48
|
/**
|
|
39
49
|
*
|
|
40
50
|
* @public
|
|
@@ -47,20 +57,20 @@ export declare class Wallet extends Base {
|
|
|
47
57
|
*
|
|
48
58
|
* @public
|
|
49
59
|
* @description Convert BIP39 Standard seed phrase to Algorand fixed 25 words mnemonic phrase
|
|
50
|
-
* @param {string}
|
|
60
|
+
* @param {string} password
|
|
51
61
|
* @param {Encrypted} encryptedSeedPhrase It needs to be encypted using wallabyAuthPubKey
|
|
52
62
|
* @returns {ConvertMnemonicSeedPhraseResponse} The mnemonic seed phrase has been converted successfully.
|
|
53
63
|
*/
|
|
54
|
-
convertMnemonicSeedphrase({
|
|
64
|
+
convertMnemonicSeedphrase({ password, encryptedSeedPhrase, }: Pick<ConvertMnemonicSeedPhraseRequest, 'password' | 'encryptedSeedPhrase'>): Promise<ConvertMnemonicSeedPhraseResponse | undefined>;
|
|
55
65
|
/**
|
|
56
66
|
*
|
|
57
67
|
* @public
|
|
58
68
|
* @description Recover the lost wallet and its assets.
|
|
59
|
-
* @param {string}
|
|
69
|
+
* @param {string} newPassword User need to set a new password while recovering the wallet
|
|
60
70
|
* @param {string} seedPhrase It needs to be encypted using wallabyAuthPubKey
|
|
61
71
|
* @returns {RecoverWalletResponse} The wallet has been recovered successfully.
|
|
62
72
|
*/
|
|
63
|
-
recover({
|
|
73
|
+
recover({ newPassword, seedPhrase, }: Omit<RecoverWalletRequest, 'clientAuthPubKey'>): Promise<RecoverWalletResponse | undefined>;
|
|
64
74
|
/**
|
|
65
75
|
*
|
|
66
76
|
* @description Get all user assets across all wallets by specifying user id
|
package/dist/routes/auth.d.ts
CHANGED
|
@@ -11,7 +11,14 @@ export declare const TransactionsRoutes: {
|
|
|
11
11
|
accessTokenRequired: boolean;
|
|
12
12
|
};
|
|
13
13
|
estimateFee: {
|
|
14
|
-
fullPath:
|
|
14
|
+
fullPath: ({ assetSymbol, originAddress, recipientAddress, amount, transactionType, tokenType, }: {
|
|
15
|
+
assetSymbol: string;
|
|
16
|
+
originAddress: string;
|
|
17
|
+
recipientAddress: string;
|
|
18
|
+
amount: number;
|
|
19
|
+
transactionType: string;
|
|
20
|
+
tokenType?: string | undefined;
|
|
21
|
+
}) => string;
|
|
15
22
|
method: RequestMothod;
|
|
16
23
|
accessTokenRequired: boolean;
|
|
17
24
|
};
|
package/dist/routes/wallet.d.ts
CHANGED
|
@@ -5,6 +5,11 @@ export declare const WalletRoutes: {
|
|
|
5
5
|
method: RequestMothod;
|
|
6
6
|
accessTokenRequired: boolean;
|
|
7
7
|
};
|
|
8
|
+
import: {
|
|
9
|
+
fullPath: string;
|
|
10
|
+
method: RequestMothod;
|
|
11
|
+
accessTokenRequired: boolean;
|
|
12
|
+
};
|
|
8
13
|
initRecoveryFlow: {
|
|
9
14
|
fullPath: string;
|
|
10
15
|
method: RequestMothod;
|
|
@@ -6,8 +6,9 @@ export declare const testUser: {
|
|
|
6
6
|
firstName: string;
|
|
7
7
|
lastName: string;
|
|
8
8
|
email: string;
|
|
9
|
-
|
|
10
|
-
|
|
9
|
+
password: string;
|
|
10
|
+
salt: string;
|
|
11
|
+
wrongPassword: string;
|
|
11
12
|
message: string;
|
|
12
13
|
hashedMessage: string;
|
|
13
14
|
signature: string;
|
package/dist/types/auth.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { User } from './common';
|
|
2
2
|
export declare type SignatureMessageRequest = {
|
|
3
|
-
|
|
3
|
+
password: string;
|
|
4
4
|
userId: string;
|
|
5
5
|
};
|
|
6
6
|
export declare type SignatureMessageResponse = {
|
|
@@ -12,26 +12,21 @@ export declare type SignatureMessageResponse = {
|
|
|
12
12
|
error?: any;
|
|
13
13
|
};
|
|
14
14
|
export declare type SignInRequest = {
|
|
15
|
-
|
|
16
|
-
};
|
|
17
|
-
export declare type SignInResponse = {
|
|
18
|
-
accessToken: string;
|
|
19
|
-
user: User;
|
|
20
|
-
error?: any;
|
|
15
|
+
password: string;
|
|
21
16
|
};
|
|
22
17
|
export declare type SignUpRequest = {
|
|
23
|
-
|
|
18
|
+
password: string;
|
|
24
19
|
firstName: string;
|
|
25
20
|
lastName: string;
|
|
26
21
|
email: string;
|
|
27
22
|
};
|
|
28
|
-
export declare type
|
|
23
|
+
export declare type AuthResponse = {
|
|
29
24
|
accessToken: string;
|
|
30
25
|
user: User;
|
|
31
26
|
error?: any;
|
|
32
27
|
};
|
|
33
28
|
export declare type ClientAuthPubKeyRequest = {
|
|
34
|
-
|
|
29
|
+
password: string;
|
|
35
30
|
userId: string;
|
|
36
31
|
message: string;
|
|
37
32
|
clientAuthPubKey: string;
|
package/dist/types/common.d.ts
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
import { Merchant, MerchantAsset } from './merchants';
|
|
2
2
|
export declare type UtilsResponse = string | undefined;
|
|
3
|
+
export declare type GetDecryptedSeedPhraseResponse = {
|
|
4
|
+
standardSeedPhrase: UtilsResponse;
|
|
5
|
+
algorandSeedPhrase: UtilsResponse;
|
|
6
|
+
};
|
|
3
7
|
export declare type WallabyError = {
|
|
4
8
|
statusCode: number;
|
|
5
9
|
message: string;
|
|
@@ -82,7 +82,7 @@ export declare type TransferRequest = {
|
|
|
82
82
|
assetId: string;
|
|
83
83
|
reference: string;
|
|
84
84
|
memo?: string;
|
|
85
|
-
|
|
85
|
+
password: string;
|
|
86
86
|
};
|
|
87
87
|
export declare type TransferResponse = {
|
|
88
88
|
transaction: Transaction;
|
|
@@ -123,5 +123,5 @@ export declare type CreateAllowanceRequest = {
|
|
|
123
123
|
contractAddress: string;
|
|
124
124
|
reference: string;
|
|
125
125
|
memo?: string;
|
|
126
|
-
|
|
126
|
+
password: string;
|
|
127
127
|
};
|
package/dist/types/wallet.d.ts
CHANGED
|
@@ -36,7 +36,7 @@ export declare type WalletAssetsResponse = {
|
|
|
36
36
|
};
|
|
37
37
|
export declare type CreateWalletRequest = {
|
|
38
38
|
userId?: string;
|
|
39
|
-
|
|
39
|
+
password: string;
|
|
40
40
|
firstName: string;
|
|
41
41
|
lastName: string;
|
|
42
42
|
email: string;
|
|
@@ -44,6 +44,17 @@ export declare type CreateWalletRequest = {
|
|
|
44
44
|
clientAuthPubKey: string;
|
|
45
45
|
signature: string;
|
|
46
46
|
};
|
|
47
|
+
export declare type ImportWalletRequest = {
|
|
48
|
+
password: string;
|
|
49
|
+
seedPhrase: string;
|
|
50
|
+
};
|
|
51
|
+
export declare type ImportWalletResponse = {
|
|
52
|
+
wallabyAuthPubKey: string;
|
|
53
|
+
assets: Array<UserAsset>;
|
|
54
|
+
encryptedSeed: Encrypted;
|
|
55
|
+
wallet: Wallet;
|
|
56
|
+
error?: any;
|
|
57
|
+
};
|
|
47
58
|
export declare type ClearWalletInput = {
|
|
48
59
|
userId: string;
|
|
49
60
|
walletId?: string;
|
|
@@ -78,7 +89,7 @@ export declare type CreateWalletResponse = {
|
|
|
78
89
|
export declare type ConvertMnemonicSeedPhraseRequest = {
|
|
79
90
|
reference: string;
|
|
80
91
|
signature: string;
|
|
81
|
-
|
|
92
|
+
password: string;
|
|
82
93
|
message: string;
|
|
83
94
|
clientAuthPubKey: string;
|
|
84
95
|
encryptedSeedPhrase: Encrypted;
|
|
@@ -93,7 +104,7 @@ export declare type ConvertMnemonicSeedPhraseResponse = {
|
|
|
93
104
|
};
|
|
94
105
|
export declare type RecoverWalletRequest = {
|
|
95
106
|
clientAuthPubKey: string;
|
|
96
|
-
|
|
107
|
+
newPassword: string;
|
|
97
108
|
seedPhrase: string;
|
|
98
109
|
};
|
|
99
110
|
export declare type RecoverWalletResponse = {
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -37,7 +37,7 @@ export default class Wallaby {
|
|
|
37
37
|
/**
|
|
38
38
|
* The `transactions` domain contains all transactions calls to Wallaby's APIs.
|
|
39
39
|
*/
|
|
40
|
-
public readonly
|
|
40
|
+
public readonly transactions: Transactions;
|
|
41
41
|
|
|
42
42
|
/**
|
|
43
43
|
* @param {string} [config.apiKey] - The API key to use for Wallaby
|
|
@@ -51,7 +51,7 @@ export default class Wallaby {
|
|
|
51
51
|
this.utils = new Utils(config);
|
|
52
52
|
this.auth = new Auth(config);
|
|
53
53
|
this.system = new System(config);
|
|
54
|
-
this.
|
|
54
|
+
this.transactions = new Transactions(config);
|
|
55
55
|
}
|
|
56
56
|
}
|
|
57
57
|
|
package/src/lib/auth/index.ts
CHANGED
|
@@ -5,9 +5,8 @@ import {
|
|
|
5
5
|
SignatureMessageRequest,
|
|
6
6
|
SignatureMessageResponse,
|
|
7
7
|
SignInRequest,
|
|
8
|
-
|
|
8
|
+
AuthResponse,
|
|
9
9
|
SignUpRequest,
|
|
10
|
-
SignUpResponse,
|
|
11
10
|
WallabyError,
|
|
12
11
|
WallabyConfig,
|
|
13
12
|
ClientAuthPubKeyRequest,
|
|
@@ -26,21 +25,21 @@ export class Auth extends Base {
|
|
|
26
25
|
*
|
|
27
26
|
* @public
|
|
28
27
|
* @description The returned message will be used to authorize the user to sign operations
|
|
29
|
-
* @param {string}
|
|
28
|
+
* @param {string} password
|
|
30
29
|
* @param {string} userId
|
|
31
30
|
* @returns {SignatureMessageResponse} The returned message will be used for sign up and sign in signature
|
|
32
31
|
*/
|
|
33
|
-
async signatureMessage({
|
|
32
|
+
async signatureMessage({ password, userId }: SignatureMessageRequest): Promise<SignatureMessageResponse | undefined> {
|
|
34
33
|
try {
|
|
35
|
-
if (!
|
|
36
|
-
|
|
34
|
+
if (!password) {
|
|
35
|
+
throw new Error('Please provide a password');
|
|
37
36
|
}
|
|
38
37
|
|
|
39
|
-
let clientAuthPubKey
|
|
40
|
-
let decryptedClientAuthPrivKey
|
|
38
|
+
let clientAuthPubKey;
|
|
39
|
+
let decryptedClientAuthPrivKey;
|
|
41
40
|
|
|
42
41
|
// If local storage doesn't already have data for the user, we create new key pair and save it
|
|
43
|
-
decryptedClientAuthPrivKey = Utils.getDecryptedPrivateKey(userId,
|
|
42
|
+
decryptedClientAuthPrivKey = Utils.getDecryptedPrivateKey(userId, password);
|
|
44
43
|
if (!decryptedClientAuthPrivKey) {
|
|
45
44
|
const { publicKey, privateKey } = createIdentity();
|
|
46
45
|
clientAuthPubKey = publicKey;
|
|
@@ -73,15 +72,15 @@ export class Auth extends Base {
|
|
|
73
72
|
*
|
|
74
73
|
* @public
|
|
75
74
|
* @description Users will be able to sign in by providing a signature and message. Use the same key pair used on sign up'
|
|
76
|
-
* @param {string}
|
|
75
|
+
* @param {string} password
|
|
77
76
|
* @param {string} firstName
|
|
78
77
|
* @param {string} lastName
|
|
79
78
|
* @param {string} email
|
|
80
79
|
* @returns {SignUpResponse}
|
|
81
80
|
*/
|
|
82
|
-
async signUp({
|
|
81
|
+
async signUp({ password, firstName, lastName, email }: SignUpRequest): Promise<AuthResponse | undefined> {
|
|
83
82
|
try {
|
|
84
|
-
const signatureMessage = await this.signatureMessage({
|
|
83
|
+
const signatureMessage = await this.signatureMessage({ password, userId: this.userId });
|
|
85
84
|
|
|
86
85
|
if (!signatureMessage || signatureMessage.error) {
|
|
87
86
|
throw new Error(signatureMessage?.error);
|
|
@@ -89,7 +88,7 @@ export class Auth extends Base {
|
|
|
89
88
|
|
|
90
89
|
const { message, signature, decryptedClientAuthPrivKey, clientAuthPubKey } = signatureMessage;
|
|
91
90
|
|
|
92
|
-
const response:
|
|
91
|
+
const response: AuthResponse = await this.request(AuthRoutes.signUp, {
|
|
93
92
|
method: AuthRoutes.signUp.method,
|
|
94
93
|
payload: { clientAuthPubKey, signature, message, firstName, lastName, email, externalUserId: this.userId },
|
|
95
94
|
});
|
|
@@ -100,7 +99,7 @@ export class Auth extends Base {
|
|
|
100
99
|
const { accessToken, user } = response;
|
|
101
100
|
Utils.setAccessToken(this.userId, accessToken);
|
|
102
101
|
Utils.setWallabyAuthPubKey(this.userId, user.wallabyAuthPubKey);
|
|
103
|
-
Utils.setEncryptedPrivateKey(this.userId, decryptedClientAuthPrivKey,
|
|
102
|
+
Utils.setEncryptedPrivateKey(this.userId, decryptedClientAuthPrivKey, password);
|
|
104
103
|
|
|
105
104
|
return response;
|
|
106
105
|
} catch (error) {
|
|
@@ -113,19 +112,19 @@ export class Auth extends Base {
|
|
|
113
112
|
*
|
|
114
113
|
* @public
|
|
115
114
|
* @description Users will be able to sign in by providing a signature and message. Use the same key pair used on sign up'
|
|
116
|
-
* @param {string}
|
|
115
|
+
* @param {string} password
|
|
117
116
|
* @returns {SignInResponse}
|
|
118
117
|
*/
|
|
119
|
-
async signIn({
|
|
118
|
+
async signIn({ password }: SignInRequest): Promise<AuthResponse | undefined> {
|
|
120
119
|
try {
|
|
121
|
-
const signatureMessage = await this.signatureMessage({
|
|
120
|
+
const signatureMessage = await this.signatureMessage({ password, userId: this.userId });
|
|
122
121
|
if (!signatureMessage || signatureMessage.error) {
|
|
123
122
|
throw new Error(signatureMessage?.error);
|
|
124
123
|
}
|
|
125
124
|
|
|
126
125
|
const { message, signature, clientAuthPubKey } = signatureMessage;
|
|
127
126
|
|
|
128
|
-
const response:
|
|
127
|
+
const response: AuthResponse = await this.request(AuthRoutes.signIn, {
|
|
129
128
|
method: AuthRoutes.signUp.method,
|
|
130
129
|
payload: { clientAuthPubKey, signature, message },
|
|
131
130
|
});
|
|
@@ -137,6 +136,10 @@ export class Auth extends Base {
|
|
|
137
136
|
const { accessToken, user } = response;
|
|
138
137
|
const wallabyAuthPubKey = Utils.getWallabyAuthPubKey(this.userId);
|
|
139
138
|
|
|
139
|
+
if (wallabyAuthPubKey !== user.wallabyAuthPubKey) {
|
|
140
|
+
throw new Error('Wallaby Auth Public Key does not match the one stored in local storage');
|
|
141
|
+
}
|
|
142
|
+
|
|
140
143
|
if (!wallabyAuthPubKey) {
|
|
141
144
|
Utils.setWallabyAuthPubKey(this.userId, user.wallabyAuthPubKey);
|
|
142
145
|
}
|
|
@@ -175,15 +178,15 @@ export class Auth extends Base {
|
|
|
175
178
|
|
|
176
179
|
/**
|
|
177
180
|
* @description Change user authentication public key
|
|
178
|
-
* @param {string}
|
|
181
|
+
* @param {string} password
|
|
179
182
|
* @param {string} userId
|
|
180
183
|
* @returns {User} User object
|
|
181
184
|
*/
|
|
182
185
|
async updateClientAuthPubKey({
|
|
183
|
-
|
|
184
|
-
}: Pick<ClientAuthPubKeyRequest, '
|
|
186
|
+
password,
|
|
187
|
+
}: Pick<ClientAuthPubKeyRequest, 'password' | 'userId'>): Promise<ClientAuthPubKeyResponse | undefined> {
|
|
185
188
|
try {
|
|
186
|
-
const signatureMessage = await this.signatureMessage({
|
|
189
|
+
const signatureMessage = await this.signatureMessage({ password, userId: this.userId });
|
|
187
190
|
if (!signatureMessage || signatureMessage.error) {
|
|
188
191
|
throw new Error(signatureMessage?.error);
|
|
189
192
|
}
|
|
@@ -205,7 +208,7 @@ export class Auth extends Base {
|
|
|
205
208
|
throw new Error(response.error);
|
|
206
209
|
}
|
|
207
210
|
// Updating private key from the newly generate key pair.
|
|
208
|
-
Utils.setEncryptedPrivateKey(this.userId, privateKey,
|
|
211
|
+
Utils.setEncryptedPrivateKey(this.userId, privateKey, password);
|
|
209
212
|
return response;
|
|
210
213
|
} catch (error) {
|
|
211
214
|
logger('SDK::Auth::clientAuthPubKey::error', error);
|
|
@@ -221,5 +224,27 @@ export class Auth extends Base {
|
|
|
221
224
|
* @returns {WallabyAuthPubKeyResponse} Returns user's Wallaby WallabyAuthPubKey
|
|
222
225
|
*/
|
|
223
226
|
async getWallabyAuthPublicKey() {}
|
|
227
|
+
|
|
228
|
+
/**
|
|
229
|
+
* @description The user salt is used to double encrypt the seedphrase before being stored
|
|
230
|
+
* in local storage.
|
|
231
|
+
* @returns {string} Returns user's salt that is generated by Wallaby system
|
|
232
|
+
*/
|
|
233
|
+
async getUserSalt(): Promise<string | undefined> {
|
|
234
|
+
try {
|
|
235
|
+
const response = await this.request(AuthRoutes.getUserSalt, {
|
|
236
|
+
method: AuthRoutes.getUserSalt.method,
|
|
237
|
+
payload: {},
|
|
238
|
+
});
|
|
239
|
+
|
|
240
|
+
if (!response || response.error) {
|
|
241
|
+
throw new Error();
|
|
242
|
+
}
|
|
243
|
+
return response.clientSalt;
|
|
244
|
+
} catch (error) {
|
|
245
|
+
logger('SDK::Auth::getUserSalt::error', error);
|
|
246
|
+
return Promise.reject(error);
|
|
247
|
+
}
|
|
248
|
+
}
|
|
224
249
|
}
|
|
225
250
|
1;
|
|
@@ -66,7 +66,7 @@ export class Transactions extends Base {
|
|
|
66
66
|
* @param {string} assetId
|
|
67
67
|
* @param {string} reference
|
|
68
68
|
* @param {string} memo
|
|
69
|
-
* @param {string}
|
|
69
|
+
* @param {string} password
|
|
70
70
|
* @returns {TransferResponse} Transaction object which contains the transaction hash and status
|
|
71
71
|
*/
|
|
72
72
|
async transfer({
|
|
@@ -76,10 +76,10 @@ export class Transactions extends Base {
|
|
|
76
76
|
assetId,
|
|
77
77
|
reference,
|
|
78
78
|
memo,
|
|
79
|
-
|
|
79
|
+
password,
|
|
80
80
|
}: TransferRequest): Promise<TransferResponse | undefined> {
|
|
81
81
|
try {
|
|
82
|
-
const signatureMessage = await this.auth.signatureMessage({
|
|
82
|
+
const signatureMessage = await this.auth.signatureMessage({ password, userId: this.userId });
|
|
83
83
|
|
|
84
84
|
if (!signatureMessage || signatureMessage.error) {
|
|
85
85
|
throw new Error(signatureMessage?.error);
|
|
@@ -133,7 +133,7 @@ export class Transactions extends Base {
|
|
|
133
133
|
transactionHash: string;
|
|
134
134
|
reference: string;
|
|
135
135
|
blockchain: BlockchainName;
|
|
136
|
-
|
|
136
|
+
password: string;
|
|
137
137
|
}): Promise<TransactionStatusResponse | undefined> {
|
|
138
138
|
try {
|
|
139
139
|
const response = await this.request(TransactionsRoutes.getTransaction, {
|
|
@@ -197,7 +197,7 @@ export class Transactions extends Base {
|
|
|
197
197
|
/**
|
|
198
198
|
*
|
|
199
199
|
* @public
|
|
200
|
-
* @param {string}
|
|
200
|
+
* @param {string} password
|
|
201
201
|
* @param {string} ownerAddress
|
|
202
202
|
* @param {string} spenderAddress
|
|
203
203
|
* @param {string} amount
|
|
@@ -209,7 +209,7 @@ export class Transactions extends Base {
|
|
|
209
209
|
*
|
|
210
210
|
*/
|
|
211
211
|
async createAllowance({
|
|
212
|
-
|
|
212
|
+
password,
|
|
213
213
|
ownerAddress,
|
|
214
214
|
spenderAddress,
|
|
215
215
|
amount,
|
|
@@ -219,7 +219,7 @@ export class Transactions extends Base {
|
|
|
219
219
|
memo,
|
|
220
220
|
}: CreateAllowanceRequest): Promise<{ transaction: Transaction } | undefined> {
|
|
221
221
|
try {
|
|
222
|
-
const signatureMessage = await this.auth.signatureMessage({
|
|
222
|
+
const signatureMessage = await this.auth.signatureMessage({ password, userId: this.userId });
|
|
223
223
|
|
|
224
224
|
if (!signatureMessage || signatureMessage.error) {
|
|
225
225
|
throw new Error(signatureMessage?.error);
|