wallaby-cash 1.3.2 → 1.3.4
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 +20 -1
- 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 +16 -10
- package/dist/lib/transactions/index.d.ts +5 -5
- package/dist/lib/utils/index.d.ts +29 -9
- package/dist/lib/utils/utils.d.ts +22 -13
- package/dist/lib/wallet/index.d.ts +34 -11
- package/dist/routes/auth.d.ts +11 -6
- package/dist/routes/merchants.d.ts +7 -7
- package/dist/routes/system.d.ts +4 -4
- package/dist/routes/transactions.d.ts +13 -6
- package/dist/routes/wallet.d.ts +15 -10
- package/dist/tests/data/user.d.ts +3 -2
- package/dist/types/auth.d.ts +5 -10
- package/dist/types/common.d.ts +5 -1
- package/dist/types/transactions.d.ts +2 -2
- package/dist/types/wallet.d.ts +13 -6
- package/package.json +2 -2
- package/src/base.ts +40 -8
- package/src/index.ts +2 -2
- package/src/lib/auth/index.ts +49 -24
- package/src/lib/transactions/index.ts +7 -7
- package/src/lib/utils/index.ts +77 -19
- package/src/lib/utils/utils.ts +96 -36
- package/src/lib/wallet/index.ts +209 -35
- package/src/routes/auth.ts +11 -6
- package/src/routes/merchants.ts +7 -7
- package/src/routes/system.ts +4 -4
- package/src/routes/transactions.ts +23 -6
- package/src/routes/wallet.ts +15 -10
- package/src/tests/auth.spec.ts +26 -24
- package/src/tests/data/user.ts +3 -2
- package/src/tests/utils.spec.ts +9 -13
- package/src/tests/wallet.spec.ts +12 -7
- package/src/types/auth.ts +5 -11
- package/src/types/common.ts +6 -1
- package/src/types/transactions.ts +2 -2
- package/src/types/wallet.ts +14 -6
|
@@ -3,26 +3,33 @@ export declare const TransactionsRoutes: {
|
|
|
3
3
|
transfer: {
|
|
4
4
|
fullPath: string;
|
|
5
5
|
method: RequestMothod;
|
|
6
|
-
|
|
6
|
+
requiresAccessToken: boolean;
|
|
7
7
|
};
|
|
8
8
|
createAllowance: {
|
|
9
9
|
fullPath: string;
|
|
10
10
|
method: RequestMothod;
|
|
11
|
-
|
|
11
|
+
requiresAccessToken: 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
|
+
requiresAccessToken: boolean;
|
|
17
24
|
};
|
|
18
25
|
getTransaction: {
|
|
19
26
|
fullPath: string;
|
|
20
27
|
method: RequestMothod;
|
|
21
|
-
|
|
28
|
+
requiresAccessToken: boolean;
|
|
22
29
|
};
|
|
23
30
|
getTransactions: {
|
|
24
31
|
fullPath: string;
|
|
25
32
|
method: RequestMothod;
|
|
26
|
-
|
|
33
|
+
requiresAccessToken: boolean;
|
|
27
34
|
};
|
|
28
35
|
};
|
package/dist/routes/wallet.d.ts
CHANGED
|
@@ -3,51 +3,56 @@ export declare const WalletRoutes: {
|
|
|
3
3
|
create: {
|
|
4
4
|
fullPath: string;
|
|
5
5
|
method: RequestMothod;
|
|
6
|
-
|
|
6
|
+
requiresAccessToken: boolean;
|
|
7
|
+
};
|
|
8
|
+
import: {
|
|
9
|
+
fullPath: string;
|
|
10
|
+
method: RequestMothod;
|
|
11
|
+
requiresAccessToken: boolean;
|
|
7
12
|
};
|
|
8
13
|
initRecoveryFlow: {
|
|
9
14
|
fullPath: string;
|
|
10
15
|
method: RequestMothod;
|
|
11
|
-
|
|
16
|
+
requiresAccessToken: boolean;
|
|
12
17
|
};
|
|
13
18
|
recover: {
|
|
14
19
|
fullPath: string;
|
|
15
20
|
method: RequestMothod;
|
|
16
|
-
|
|
21
|
+
requiresAccessToken: boolean;
|
|
17
22
|
};
|
|
18
23
|
getTokenBalance: {
|
|
19
24
|
fullPath: ({ address, symbol, tokenStandard }: TokenBalanceRequest) => string;
|
|
20
25
|
method: RequestMothod;
|
|
21
|
-
|
|
26
|
+
requiresAccessToken: boolean;
|
|
22
27
|
};
|
|
23
28
|
estimateFee: {
|
|
24
29
|
fullPath: string;
|
|
25
30
|
method: RequestMothod;
|
|
26
|
-
|
|
31
|
+
requiresAccessToken: boolean;
|
|
27
32
|
};
|
|
28
33
|
getWalletAssets: {
|
|
29
34
|
fullPath: ({ walletId }: QueryWalletRequest) => string;
|
|
30
35
|
method: RequestMothod;
|
|
31
|
-
|
|
36
|
+
requiresAccessToken: boolean;
|
|
32
37
|
};
|
|
33
38
|
getUserAssets: {
|
|
34
39
|
fullPath: ({ userId }: QueryUserRequest) => string;
|
|
35
40
|
method: RequestMothod;
|
|
36
|
-
|
|
41
|
+
requiresAccessToken: boolean;
|
|
37
42
|
};
|
|
38
43
|
getUserWallets: {
|
|
39
44
|
fullPath: ({ userId }: QueryUserRequest) => string;
|
|
40
45
|
method: RequestMothod;
|
|
41
|
-
|
|
46
|
+
requiresAccessToken: boolean;
|
|
42
47
|
};
|
|
43
48
|
convertMnemonicSeedphrase: {
|
|
44
49
|
fullPath: string;
|
|
45
50
|
method: RequestMothod;
|
|
46
|
-
|
|
51
|
+
requiresAccessToken: boolean;
|
|
47
52
|
};
|
|
48
53
|
createMultisigAsset: {
|
|
49
54
|
fullPath: string;
|
|
50
55
|
method: RequestMothod;
|
|
51
|
-
|
|
56
|
+
requiresAccessToken: boolean;
|
|
52
57
|
};
|
|
53
58
|
};
|
|
@@ -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;
|
|
@@ -165,7 +169,7 @@ export declare interface RequestOptions extends RequestInit {
|
|
|
165
169
|
export declare type RequestRoute = {
|
|
166
170
|
fullPath: string | ((params: any) => string);
|
|
167
171
|
method: RequestMothod;
|
|
168
|
-
|
|
172
|
+
requiresAccessToken: boolean;
|
|
169
173
|
};
|
|
170
174
|
export declare enum ApiKeyStatus {
|
|
171
175
|
Active = "active",
|
|
@@ -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,9 +44,16 @@ export declare type CreateWalletRequest = {
|
|
|
44
44
|
clientAuthPubKey: string;
|
|
45
45
|
signature: string;
|
|
46
46
|
};
|
|
47
|
-
export declare type
|
|
48
|
-
|
|
49
|
-
|
|
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;
|
|
50
57
|
};
|
|
51
58
|
export declare type Wallet = {
|
|
52
59
|
id: string;
|
|
@@ -78,7 +85,7 @@ export declare type CreateWalletResponse = {
|
|
|
78
85
|
export declare type ConvertMnemonicSeedPhraseRequest = {
|
|
79
86
|
reference: string;
|
|
80
87
|
signature: string;
|
|
81
|
-
|
|
88
|
+
password: string;
|
|
82
89
|
message: string;
|
|
83
90
|
clientAuthPubKey: string;
|
|
84
91
|
encryptedSeedPhrase: Encrypted;
|
|
@@ -93,7 +100,7 @@ export declare type ConvertMnemonicSeedPhraseResponse = {
|
|
|
93
100
|
};
|
|
94
101
|
export declare type RecoverWalletRequest = {
|
|
95
102
|
clientAuthPubKey: string;
|
|
96
|
-
|
|
103
|
+
newPassword: string;
|
|
97
104
|
seedPhrase: string;
|
|
98
105
|
};
|
|
99
106
|
export declare type RecoverWalletResponse = {
|
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "wallaby-cash",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.4",
|
|
4
4
|
"license": "MIT",
|
|
5
|
-
"repository": "https://github.com/
|
|
5
|
+
"repository": "https://github.com/WALLABY-WaaS/wallaby-sdk-js",
|
|
6
6
|
"main": "./dist/index.js",
|
|
7
7
|
"module": "./dist/index.esm.js",
|
|
8
8
|
"exports": {
|
package/src/base.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import axios, { AxiosError } from 'axios';
|
|
2
|
-
import { WallabyConfig, RequestMothod, RequestOptions, RequestRoute } from './types';
|
|
3
|
-
import { getAccessToken } from './lib/utils/utils';
|
|
2
|
+
import { WallabyConfig, RequestMothod, RequestOptions, RequestRoute, SeedPhraseType } from './types';
|
|
3
|
+
import { getAccessToken, getEncryptedPrivateKey, getEncryptedSeedPhrase, getWallabyAuthPubKey } from './lib/utils/utils';
|
|
4
4
|
import logger from './helpers/logger';
|
|
5
5
|
|
|
6
6
|
export abstract class Base {
|
|
@@ -16,6 +16,18 @@ export abstract class Base {
|
|
|
16
16
|
this.jwt = config.jwt;
|
|
17
17
|
}
|
|
18
18
|
|
|
19
|
+
protected get device() {
|
|
20
|
+
return this.loadDeviceInformation();
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
private get settings() {
|
|
24
|
+
return {
|
|
25
|
+
apiKey: this.apiKey,
|
|
26
|
+
baseUrl: this.baseUrl,
|
|
27
|
+
env: process.env.NODE_ENV,
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
|
|
19
31
|
protected async request<T>(route: RequestRoute, options?: RequestOptions): Promise<T | any> {
|
|
20
32
|
try {
|
|
21
33
|
let url;
|
|
@@ -24,7 +36,7 @@ export abstract class Base {
|
|
|
24
36
|
} else {
|
|
25
37
|
url = route.fullPath;
|
|
26
38
|
}
|
|
27
|
-
const headers = this.getRequestHeaders(route.
|
|
39
|
+
const headers = this.getRequestHeaders(route.requiresAccessToken);
|
|
28
40
|
|
|
29
41
|
const http = axios.create({
|
|
30
42
|
url: url,
|
|
@@ -78,18 +90,38 @@ export abstract class Base {
|
|
|
78
90
|
}
|
|
79
91
|
}
|
|
80
92
|
|
|
81
|
-
|
|
93
|
+
private getRequestHeaders(requiresAccessToken: boolean) {
|
|
82
94
|
let headers: any = {
|
|
83
95
|
'Content-Type': 'application/json',
|
|
84
|
-
'x-api-key': this.apiKey,
|
|
85
|
-
'x-client-jwt': this.
|
|
96
|
+
'x-api-key': this.settings.apiKey,
|
|
97
|
+
'x-client-jwt': this.device.authTokens.clientAuthToken,
|
|
86
98
|
};
|
|
87
|
-
if (
|
|
99
|
+
if (requiresAccessToken && this.userId) {
|
|
88
100
|
headers = {
|
|
89
101
|
...headers,
|
|
90
|
-
Authorization: 'Bearer ' +
|
|
102
|
+
Authorization: 'Bearer ' + this.device.authTokens.accessToken,
|
|
91
103
|
};
|
|
92
104
|
}
|
|
93
105
|
return headers;
|
|
94
106
|
}
|
|
107
|
+
|
|
108
|
+
private loadDeviceInformation() {
|
|
109
|
+
return {
|
|
110
|
+
authTokens: {
|
|
111
|
+
accessToken: getAccessToken(this.userId),
|
|
112
|
+
clientAuthToken: this.jwt,
|
|
113
|
+
},
|
|
114
|
+
user: {
|
|
115
|
+
clientUserId: this.userId,
|
|
116
|
+
encryptedStandardSeedPhrase: getEncryptedSeedPhrase(this.userId, SeedPhraseType.Standard),
|
|
117
|
+
encryptedAlgorandSeedPhrase: getEncryptedSeedPhrase(this.userId, SeedPhraseType.Algorand),
|
|
118
|
+
wallabyUserId: undefined,
|
|
119
|
+
},
|
|
120
|
+
encrytionKeys: {
|
|
121
|
+
deviceEncryptedPrivateKey: getEncryptedPrivateKey(this.userId),
|
|
122
|
+
devicePublicKey: undefined, // initially this is undefined, because we don't have the decrypted private key yet
|
|
123
|
+
apiPublicKey: getWallabyAuthPubKey(this.userId),
|
|
124
|
+
},
|
|
125
|
+
};
|
|
126
|
+
}
|
|
95
127
|
}
|
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
|
-
* @returns {
|
|
79
|
+
* @returns { AuthResponse }
|
|
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);
|