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
package/src/tests/auth.spec.ts
CHANGED
|
@@ -8,7 +8,7 @@ import axios from 'axios';
|
|
|
8
8
|
describe('Auth Functions', () => {
|
|
9
9
|
const {
|
|
10
10
|
id,
|
|
11
|
-
|
|
11
|
+
password,
|
|
12
12
|
firstName,
|
|
13
13
|
lastName,
|
|
14
14
|
email,
|
|
@@ -34,24 +34,24 @@ describe('Auth Functions', () => {
|
|
|
34
34
|
mockAxiosSpy.mockRestore()
|
|
35
35
|
})
|
|
36
36
|
it('Returns undefined if hash key is not provided', async () => {
|
|
37
|
-
const
|
|
38
|
-
const response = await wallaby.auth.signatureMessage({
|
|
37
|
+
const emtpypassword = '';
|
|
38
|
+
const response = await wallaby.auth.signatureMessage({ password: emtpypassword, userId: id });
|
|
39
39
|
expect(response).toBeUndefined();
|
|
40
40
|
});
|
|
41
41
|
it('Creates new key pair if private key is not found', async () => {
|
|
42
|
-
const response = await wallaby.auth.signatureMessage({
|
|
42
|
+
const response = await wallaby.auth.signatureMessage({ password, userId: id });
|
|
43
43
|
console.log('response private key is not found', response);
|
|
44
44
|
expect(response?.clientAuthPubKey).not.toEqual(testUser.publicKey);
|
|
45
45
|
expect(response?.decryptedClientAuthPrivKey).not.toEqual(testUser.privateKey);
|
|
46
46
|
});
|
|
47
47
|
it('Fetches private key from local storage successfully', async () => {
|
|
48
|
-
setEncryptedPrivateKey(testUser.id, testUser.privateKey, testUser.
|
|
49
|
-
const response = await wallaby.auth.signatureMessage({
|
|
48
|
+
setEncryptedPrivateKey(testUser.id, testUser.privateKey, testUser.password);
|
|
49
|
+
const response = await wallaby.auth.signatureMessage({ password, userId: id });
|
|
50
50
|
expect(response?.decryptedClientAuthPrivKey).toEqual(testUser.privateKey);
|
|
51
51
|
expect(response?.clientAuthPubKey).toEqual(testUser.publicKey);
|
|
52
52
|
});
|
|
53
53
|
it('Returns all response properties', async () => {
|
|
54
|
-
const response = await wallaby.auth.signatureMessage({
|
|
54
|
+
const response = await wallaby.auth.signatureMessage({ password, userId: id });
|
|
55
55
|
const { message, decryptedClientAuthPrivKey, clientAuthPubKey, hashedMessage, signature } =
|
|
56
56
|
response as SignatureMessageResponse;
|
|
57
57
|
expect(decryptedClientAuthPrivKey).toBeDefined();
|
|
@@ -96,18 +96,18 @@ describe('Auth Functions', () => {
|
|
|
96
96
|
// })
|
|
97
97
|
});
|
|
98
98
|
it('Calls signatureMessage to get a new message', async () => {
|
|
99
|
-
await wallaby.auth.signUp({
|
|
99
|
+
await wallaby.auth.signUp({ password, firstName, lastName, email });
|
|
100
100
|
|
|
101
101
|
expect(wallaby.auth.signatureMessage).toHaveBeenCalled();
|
|
102
102
|
});
|
|
103
103
|
it('Has access token in response and stores it successfully', async () => {
|
|
104
|
-
const response = await wallaby.auth.signUp({
|
|
104
|
+
const response = await wallaby.auth.signUp({ password, firstName, lastName, email });
|
|
105
105
|
const { accessToken } = response as SignUpResponse;
|
|
106
106
|
expect(accessToken).toEqual(testAccessToken);
|
|
107
107
|
expect(getAccessToken(id)).toBeDefined()
|
|
108
108
|
});
|
|
109
109
|
it('Has user Wallaby ID and Wallaby AuthPubKey', async () => {
|
|
110
|
-
const response = await wallaby.auth.signUp({
|
|
110
|
+
const response = await wallaby.auth.signUp({ password, firstName, lastName, email });
|
|
111
111
|
const { user } = response as SignUpResponse;
|
|
112
112
|
expect(user.wallabyAuthPubKey).toEqual(wallabyAuthPublicKey);
|
|
113
113
|
expect(user.id).toBe(wallabyUserId)
|
package/src/tests/data/user.ts
CHANGED
|
@@ -6,8 +6,9 @@ export const testUser = {
|
|
|
6
6
|
firstName: 'Joanna',
|
|
7
7
|
lastName: 'Smith',
|
|
8
8
|
email: 'joanna.smith@yopmail.com',
|
|
9
|
-
|
|
10
|
-
|
|
9
|
+
password: '16charencryption',
|
|
10
|
+
salt: 'SomeSaltyStringThatIsUsedInEncryption',
|
|
11
|
+
wrongPassword: '17charencryption!',
|
|
11
12
|
message: 'c25d687f94ab48bfa87baeef4a2741ab',
|
|
12
13
|
hashedMessage: '0x721edfb991965324620d2259fd1e0e1f19f36eb46d9cd8ada68686bc3f7cc5d1',
|
|
13
14
|
signature: '0x9b765cea1d8fec0c1c4f51567dfcd5554fc0fad82074049f10ad5d6d1db46d253155f7793d9f88d55ff3fce28c0112528fde02962eab9e04089715e048ae9ce51b',
|
package/src/tests/utils.spec.ts
CHANGED
|
@@ -9,18 +9,12 @@ import {
|
|
|
9
9
|
getDecryptedPrivateKey,
|
|
10
10
|
setEncryptedSeedPhrase,
|
|
11
11
|
getEncryptedSeedPhrase,
|
|
12
|
-
validatePassword,
|
|
13
12
|
} from '../lib/utils/utils';
|
|
14
13
|
import { SeedPhraseType } from '../types';
|
|
15
14
|
import { testUser } from './data';
|
|
16
|
-
// import { LocalStorage } from 'node-localstorage';
|
|
17
|
-
|
|
18
|
-
// back to this temp solution
|
|
19
|
-
// const tempLocalStorage = new LocalStorage(`${__dirname}/../../tests/temp`);
|
|
20
|
-
// const tempLocalStorage = require('./__mocks__/localStorageMock');
|
|
21
15
|
|
|
22
16
|
describe('Utilities functions', () => {
|
|
23
|
-
const { id,
|
|
17
|
+
const { id, password, salt, wrongPassword, seedPhrase, privateKey, publicKey } = testUser;
|
|
24
18
|
|
|
25
19
|
describe('WallabyAuthPublicKey', () => {
|
|
26
20
|
const setterResult = setWallabyAuthPubKey(id, publicKey);
|
|
@@ -34,7 +28,7 @@ describe('Utilities functions', () => {
|
|
|
34
28
|
});
|
|
35
29
|
|
|
36
30
|
describe('ClientAuthPrivateKey', () => {
|
|
37
|
-
const setterResult = setEncryptedPrivateKey(id, privateKey,
|
|
31
|
+
const setterResult = setEncryptedPrivateKey(id, privateKey, password);
|
|
38
32
|
const getterResult = getEncryptedPrivateKey(id);
|
|
39
33
|
it('stores key to local storage and returns true', () => {
|
|
40
34
|
expect(setterResult).toBeTruthy();
|
|
@@ -45,21 +39,22 @@ describe('Utilities functions', () => {
|
|
|
45
39
|
it('stores client auth private key in local storage', () => {
|
|
46
40
|
expect(getterResult).toBeDefined();
|
|
47
41
|
});
|
|
48
|
-
it('decrypts private key if
|
|
49
|
-
const decryptedResult = getDecryptedPrivateKey(id,
|
|
42
|
+
it('decrypts private key if password is correct', () => {
|
|
43
|
+
const decryptedResult = getDecryptedPrivateKey(id, password);
|
|
50
44
|
expect(decryptedResult).toBeDefined();
|
|
51
45
|
expect(decryptedResult).toEqual(privateKey);
|
|
52
46
|
});
|
|
53
|
-
it('returns an error if
|
|
47
|
+
it('returns an error if password is incorrect', () => {
|
|
54
48
|
localStorage.removeItem(`${process.env.NODE_ENV}-client-auth-private-key-${id}`);
|
|
55
|
-
const decryptedResult = getDecryptedPrivateKey(id,
|
|
49
|
+
const decryptedResult = getDecryptedPrivateKey(id, wrongPassword);
|
|
56
50
|
expect(decryptedResult).toBeUndefined();
|
|
57
51
|
});
|
|
58
52
|
});
|
|
59
53
|
|
|
60
54
|
describe('EncryptedSeedPhrase storing and fetching', () => {
|
|
61
55
|
it('stores seedPhrase in local storage', async () => {
|
|
62
|
-
const seedPhraseIsSet = await setEncryptedSeedPhrase(id, publicKey, seedPhrase, SeedPhraseType.Standard);
|
|
56
|
+
const seedPhraseIsSet = await setEncryptedSeedPhrase(id, publicKey, seedPhrase, SeedPhraseType.Standard, salt, password);
|
|
57
|
+
console.log('seedPhraseIsSet', seedPhraseIsSet);
|
|
63
58
|
expect(seedPhraseIsSet).toBeTruthy();
|
|
64
59
|
});
|
|
65
60
|
it('encrypts seedPhrase before storing it', async () => {
|
package/src/tests/wallet.spec.ts
CHANGED
|
@@ -4,7 +4,7 @@ import { SeedPhraseType } from '../types';
|
|
|
4
4
|
import { config, testUser } from './data';
|
|
5
5
|
const wallaby = new Wallaby(config);
|
|
6
6
|
|
|
7
|
-
const { id,
|
|
7
|
+
const { id, password, testAccessToken, privateKey, seedPhrase, wallabyAuthPublicKey, publicKey, salt } = testUser;
|
|
8
8
|
|
|
9
9
|
describe('Wallet Functions', () => {
|
|
10
10
|
describe('getTokenBalance()', () => {
|
|
@@ -16,14 +16,14 @@ describe('Wallet Functions', () => {
|
|
|
16
16
|
it('clears wallet data from local storage', async () => {
|
|
17
17
|
// Set the test data first
|
|
18
18
|
Utils.setAccessToken(id, testAccessToken);
|
|
19
|
-
Utils.setEncryptedPrivateKey(id, privateKey,
|
|
19
|
+
Utils.setEncryptedPrivateKey(id, privateKey, password);
|
|
20
20
|
Utils.setWallabyAuthPubKey(id, wallabyAuthPublicKey);
|
|
21
|
-
Utils.setEncryptedSeedPhrase(id, publicKey, seedPhrase, SeedPhraseType.Standard);
|
|
21
|
+
Utils.setEncryptedSeedPhrase(id, publicKey, seedPhrase, SeedPhraseType.Standard, password, salt);
|
|
22
22
|
// Clear local storage
|
|
23
23
|
wallaby.wallet.clearWalletData({ userId: id });
|
|
24
24
|
// Fetch Items from local storage after clearing
|
|
25
|
-
const decryptedPrivateKey = Utils.getDecryptedPrivateKey(id,
|
|
26
|
-
const standardSeedphrase = await Utils.getDecryptedSeedPhrase(id,
|
|
25
|
+
const decryptedPrivateKey = Utils.getDecryptedPrivateKey(id, password);
|
|
26
|
+
const standardSeedphrase = await Utils.getDecryptedSeedPhrase(id, password, salt, SeedPhraseType.Standard);
|
|
27
27
|
const wallabyPublicKey = Utils.getWallabyAuthPubKey(id);
|
|
28
28
|
const accessToken = Utils.getAccessToken(id);
|
|
29
29
|
|
package/src/types/auth.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { User } from './common';
|
|
2
2
|
|
|
3
3
|
export declare type SignatureMessageRequest = {
|
|
4
|
-
|
|
4
|
+
password: string;
|
|
5
5
|
userId: string;
|
|
6
6
|
};
|
|
7
7
|
|
|
@@ -15,30 +15,24 @@ export declare type SignatureMessageResponse = {
|
|
|
15
15
|
};
|
|
16
16
|
|
|
17
17
|
export declare type SignInRequest = {
|
|
18
|
-
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
export declare type SignInResponse = {
|
|
22
|
-
accessToken: string;
|
|
23
|
-
user: User;
|
|
24
|
-
error?: any;
|
|
18
|
+
password: string;
|
|
25
19
|
};
|
|
26
20
|
|
|
27
21
|
export declare type SignUpRequest = {
|
|
28
|
-
|
|
22
|
+
password: string;
|
|
29
23
|
firstName: string;
|
|
30
24
|
lastName: string;
|
|
31
25
|
email: string;
|
|
32
26
|
};
|
|
33
27
|
|
|
34
|
-
export declare type
|
|
28
|
+
export declare type AuthResponse = {
|
|
35
29
|
accessToken: string;
|
|
36
30
|
user: User;
|
|
37
31
|
error?: any;
|
|
38
32
|
};
|
|
39
33
|
|
|
40
34
|
export declare type ClientAuthPubKeyRequest = {
|
|
41
|
-
|
|
35
|
+
password: string;
|
|
42
36
|
userId: string;
|
|
43
37
|
message: string;
|
|
44
38
|
clientAuthPubKey: string;
|
package/src/types/common.ts
CHANGED
|
@@ -2,6 +2,11 @@ import { Merchant, MerchantAsset } from './merchants';
|
|
|
2
2
|
|
|
3
3
|
export declare type UtilsResponse = string | undefined;
|
|
4
4
|
|
|
5
|
+
export declare type GetDecryptedSeedPhraseResponse = {
|
|
6
|
+
standardSeedPhrase: UtilsResponse;
|
|
7
|
+
algorandSeedPhrase: UtilsResponse;
|
|
8
|
+
};
|
|
9
|
+
|
|
5
10
|
export declare type WallabyError = {
|
|
6
11
|
statusCode: number;
|
|
7
12
|
message: string;
|
|
@@ -89,7 +89,7 @@ export declare type TransferRequest = {
|
|
|
89
89
|
assetId: string;
|
|
90
90
|
reference: string;
|
|
91
91
|
memo?: string;
|
|
92
|
-
|
|
92
|
+
password: string;
|
|
93
93
|
};
|
|
94
94
|
|
|
95
95
|
export declare type TransferResponse = {
|
|
@@ -135,5 +135,5 @@ export declare type CreateAllowanceRequest = {
|
|
|
135
135
|
contractAddress: string;
|
|
136
136
|
reference: string;
|
|
137
137
|
memo?: string;
|
|
138
|
-
|
|
138
|
+
password: string;
|
|
139
139
|
};
|
package/src/types/wallet.ts
CHANGED
|
@@ -45,7 +45,7 @@ export declare type WalletAssetsResponse = {
|
|
|
45
45
|
|
|
46
46
|
export declare type CreateWalletRequest = {
|
|
47
47
|
userId?: string;
|
|
48
|
-
|
|
48
|
+
password: string;
|
|
49
49
|
firstName: string;
|
|
50
50
|
lastName: string;
|
|
51
51
|
email: string;
|
|
@@ -54,6 +54,19 @@ export declare type CreateWalletRequest = {
|
|
|
54
54
|
signature: string;
|
|
55
55
|
};
|
|
56
56
|
|
|
57
|
+
export declare type ImportWalletRequest = {
|
|
58
|
+
password: string;
|
|
59
|
+
seedPhrase: string;
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
export declare type ImportWalletResponse = {
|
|
63
|
+
wallabyAuthPubKey: string;
|
|
64
|
+
assets: Array<UserAsset>;
|
|
65
|
+
encryptedSeed: Encrypted;
|
|
66
|
+
wallet: Wallet;
|
|
67
|
+
error?: any;
|
|
68
|
+
};
|
|
69
|
+
|
|
57
70
|
export declare type ClearWalletInput = {
|
|
58
71
|
userId: string;
|
|
59
72
|
walletId?: string;
|
|
@@ -91,7 +104,7 @@ export declare type CreateWalletResponse = {
|
|
|
91
104
|
export declare type ConvertMnemonicSeedPhraseRequest = {
|
|
92
105
|
reference: string;
|
|
93
106
|
signature: string;
|
|
94
|
-
|
|
107
|
+
password: string;
|
|
95
108
|
message: string;
|
|
96
109
|
clientAuthPubKey: string;
|
|
97
110
|
encryptedSeedPhrase: Encrypted;
|
|
@@ -108,7 +121,7 @@ export declare type ConvertMnemonicSeedPhraseResponse = {
|
|
|
108
121
|
|
|
109
122
|
export declare type RecoverWalletRequest = {
|
|
110
123
|
clientAuthPubKey: string;
|
|
111
|
-
|
|
124
|
+
newPassword: string;
|
|
112
125
|
seedPhrase: string;
|
|
113
126
|
};
|
|
114
127
|
|