hive-keychain-commons 1.6.0 → 1.7.0
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/lib/interfaces/keychain.d.ts +32 -4
- package/lib/interfaces/keychain.js +3 -0
- package/lib/interfaces/vsc.d.ts +14 -2
- package/lib/interfaces/vsc.js +11 -1
- package/lib/utils/vsc.utils.d.ts +1 -1
- package/lib/utils/vsc.utils.js +17 -16
- package/package.json +1 -1
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { Operation, Transaction } from '@hiveio/dhive';
|
|
2
2
|
import { IStep } from '../swaps/swap.interface';
|
|
3
|
+
import { VscRequestParams, VscStakingOperation } from './vsc';
|
|
3
4
|
export declare enum KeychainRequestTypes {
|
|
4
5
|
decode = "decode",
|
|
5
6
|
encode = "encode",
|
|
@@ -31,7 +32,10 @@ export declare enum KeychainRequestTypes {
|
|
|
31
32
|
recurrentTransfer = "recurrentTransfer",
|
|
32
33
|
swap = "swap",
|
|
33
34
|
vscCallContract = "vscCallContract",
|
|
34
|
-
vscDeposit = "vscDeposit"
|
|
35
|
+
vscDeposit = "vscDeposit",
|
|
36
|
+
vscWithdrawal = "vscWithdrawal",
|
|
37
|
+
vscTransfer = "vscTransfer",
|
|
38
|
+
vscStaking = "vscStaking"
|
|
35
39
|
}
|
|
36
40
|
export declare enum KeychainKeyTypes {
|
|
37
41
|
posting = "Posting",
|
|
@@ -271,14 +275,38 @@ export type RequestVscCallContract = CommonRequestParams & {
|
|
|
271
275
|
payload: object;
|
|
272
276
|
method: KeychainKeyTypes.posting | KeychainKeyTypes.active;
|
|
273
277
|
};
|
|
274
|
-
export type
|
|
278
|
+
export type RequestVscDeposit = CommonRequestParams & {
|
|
275
279
|
type: KeychainRequestTypes.vscDeposit;
|
|
276
280
|
username?: string;
|
|
277
|
-
|
|
281
|
+
to?: string;
|
|
278
282
|
amount: string;
|
|
279
283
|
currency: string;
|
|
280
284
|
};
|
|
281
|
-
export type
|
|
285
|
+
export type RequestVscWithdrawal = CommonRequestParams & VscRequestParams & {
|
|
286
|
+
type: KeychainRequestTypes.vscWithdrawal;
|
|
287
|
+
username?: string;
|
|
288
|
+
to: string;
|
|
289
|
+
amount: string;
|
|
290
|
+
currency: string;
|
|
291
|
+
memo: string;
|
|
292
|
+
};
|
|
293
|
+
export type RequestVscTransfer = CommonRequestParams & VscRequestParams & {
|
|
294
|
+
type: KeychainRequestTypes.vscTransfer;
|
|
295
|
+
username?: string;
|
|
296
|
+
to: string;
|
|
297
|
+
amount: string;
|
|
298
|
+
currency: string;
|
|
299
|
+
memo: string;
|
|
300
|
+
};
|
|
301
|
+
export type RequestVscStaking = CommonRequestParams & VscRequestParams & {
|
|
302
|
+
type: KeychainRequestTypes.vscStaking;
|
|
303
|
+
username?: string;
|
|
304
|
+
to: string;
|
|
305
|
+
amount: string;
|
|
306
|
+
currency: string;
|
|
307
|
+
operation: VscStakingOperation;
|
|
308
|
+
};
|
|
309
|
+
export type KeychainRequestData = (RequestDecode | RequestEncodeWithKeys | RequestEncode | RequestSignBuffer | RequestBroadcast | RequestAddAccountAuthority | RequestRemoveAccountAuthority | RequestAddKeyAuthority | RequestRemoveKeyAuthority | RequestSignTx | RequestPost | RequestVote | RequestCustomJSON | RequestSignedCall | RequestTransfer | RequestSendToken | RequestDelegation | RequestWitnessVote | RequestProxy | RequestPowerUp | RequestPowerDown | RequestCreateClaimedAccount | RequestUpdateProposalVote | RequestCreateProposal | RequestRemoveProposal | RequestAddAccount | RequestConvert | RequestRecurrentTransfer | RequestSwap | RequestVscCallContract | RequestVscDeposit | RequestVscWithdrawal | RequestVscTransfer | RequestVscStaking) & {
|
|
282
310
|
redirect_uri?: string;
|
|
283
311
|
};
|
|
284
312
|
export type RequestId = {
|
|
@@ -34,6 +34,9 @@ var KeychainRequestTypes;
|
|
|
34
34
|
KeychainRequestTypes["swap"] = "swap";
|
|
35
35
|
KeychainRequestTypes["vscCallContract"] = "vscCallContract";
|
|
36
36
|
KeychainRequestTypes["vscDeposit"] = "vscDeposit";
|
|
37
|
+
KeychainRequestTypes["vscWithdrawal"] = "vscWithdrawal";
|
|
38
|
+
KeychainRequestTypes["vscTransfer"] = "vscTransfer";
|
|
39
|
+
KeychainRequestTypes["vscStaking"] = "vscStaking";
|
|
37
40
|
})(KeychainRequestTypes = exports.KeychainRequestTypes || (exports.KeychainRequestTypes = {}));
|
|
38
41
|
var KeychainKeyTypes;
|
|
39
42
|
(function (KeychainKeyTypes) {
|
package/lib/interfaces/vsc.d.ts
CHANGED
|
@@ -1,11 +1,16 @@
|
|
|
1
1
|
export declare enum VscStatus {
|
|
2
2
|
UNCONFIRMED = "UNCONFIRMED",
|
|
3
3
|
CONFIRMED = "CONFIRMED",
|
|
4
|
-
INCLUDED = "INCLUDED"
|
|
4
|
+
INCLUDED = "INCLUDED",
|
|
5
|
+
FAILED = "FAILED"
|
|
5
6
|
}
|
|
6
7
|
export declare enum VscHistoryType {
|
|
7
8
|
CONTRACT_CALL = "CONTRACT_CALL",
|
|
8
|
-
TRANSFER = "TRANSFER"
|
|
9
|
+
TRANSFER = "TRANSFER",
|
|
10
|
+
DEPOSIT = "DEPOSIT",
|
|
11
|
+
WITHDRAW = "WITHDRAW",
|
|
12
|
+
STAKING = "STAKING",
|
|
13
|
+
UNSTAKING = "UNSTAKING"
|
|
9
14
|
}
|
|
10
15
|
export declare enum VscLedgerType {
|
|
11
16
|
WITHDRAW = "withdraw",
|
|
@@ -15,6 +20,13 @@ export declare enum VscToken {
|
|
|
15
20
|
HIVE = "HIVE",
|
|
16
21
|
HBD = "HBD"
|
|
17
22
|
}
|
|
23
|
+
export declare enum VscStakingOperation {
|
|
24
|
+
STAKING = "STAKING",
|
|
25
|
+
UNSTAKING = "UNSTAKING"
|
|
26
|
+
}
|
|
27
|
+
export type VscRequestParams = {
|
|
28
|
+
netId?: string;
|
|
29
|
+
};
|
|
18
30
|
export type VscHistoryResponse = {
|
|
19
31
|
findLedgerTXs: {
|
|
20
32
|
txs: VscTransfer[];
|
package/lib/interfaces/vsc.js
CHANGED
|
@@ -1,16 +1,21 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.VscToken = exports.VscLedgerType = exports.VscHistoryType = exports.VscStatus = void 0;
|
|
3
|
+
exports.VscStakingOperation = exports.VscToken = exports.VscLedgerType = exports.VscHistoryType = exports.VscStatus = void 0;
|
|
4
4
|
var VscStatus;
|
|
5
5
|
(function (VscStatus) {
|
|
6
6
|
VscStatus["UNCONFIRMED"] = "UNCONFIRMED";
|
|
7
7
|
VscStatus["CONFIRMED"] = "CONFIRMED";
|
|
8
8
|
VscStatus["INCLUDED"] = "INCLUDED";
|
|
9
|
+
VscStatus["FAILED"] = "FAILED";
|
|
9
10
|
})(VscStatus = exports.VscStatus || (exports.VscStatus = {}));
|
|
10
11
|
var VscHistoryType;
|
|
11
12
|
(function (VscHistoryType) {
|
|
12
13
|
VscHistoryType["CONTRACT_CALL"] = "CONTRACT_CALL";
|
|
13
14
|
VscHistoryType["TRANSFER"] = "TRANSFER";
|
|
15
|
+
VscHistoryType["DEPOSIT"] = "DEPOSIT";
|
|
16
|
+
VscHistoryType["WITHDRAW"] = "WITHDRAW";
|
|
17
|
+
VscHistoryType["STAKING"] = "STAKING";
|
|
18
|
+
VscHistoryType["UNSTAKING"] = "UNSTAKING";
|
|
14
19
|
})(VscHistoryType = exports.VscHistoryType || (exports.VscHistoryType = {}));
|
|
15
20
|
var VscLedgerType;
|
|
16
21
|
(function (VscLedgerType) {
|
|
@@ -22,3 +27,8 @@ var VscToken;
|
|
|
22
27
|
VscToken["HIVE"] = "HIVE";
|
|
23
28
|
VscToken["HBD"] = "HBD";
|
|
24
29
|
})(VscToken = exports.VscToken || (exports.VscToken = {}));
|
|
30
|
+
var VscStakingOperation;
|
|
31
|
+
(function (VscStakingOperation) {
|
|
32
|
+
VscStakingOperation["STAKING"] = "STAKING";
|
|
33
|
+
VscStakingOperation["UNSTAKING"] = "UNSTAKING";
|
|
34
|
+
})(VscStakingOperation = exports.VscStakingOperation || (exports.VscStakingOperation = {}));
|
package/lib/utils/vsc.utils.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { VscHistoryType, VscStatus } from '../interfaces/vsc';
|
|
2
2
|
export declare const VscUtils: {
|
|
3
3
|
checkStatus: (id: string, type: VscHistoryType) => Promise<VscStatus>;
|
|
4
|
-
waitForStatus: (id: string, type: VscHistoryType) => Promise<VscStatus>;
|
|
4
|
+
waitForStatus: (id: string, type: VscHistoryType, maxIterations?: number, wait?: number) => Promise<VscStatus>;
|
|
5
5
|
getOrganizedHistory: (username: string) => Promise<(import("../interfaces/vsc").VscTransfer | import("../interfaces/vsc").VscCall)[]>;
|
|
6
6
|
getAddressFromDid: (did: string) => string | undefined;
|
|
7
7
|
};
|
package/lib/utils/vsc.utils.js
CHANGED
|
@@ -16,46 +16,47 @@ exports.VscUtils = void 0;
|
|
|
16
16
|
const moment_1 = __importDefault(require("moment"));
|
|
17
17
|
const config_1 = __importDefault(require("../config"));
|
|
18
18
|
const vsc_1 = require("../interfaces/vsc");
|
|
19
|
-
const waitForStatus = (id, type) => __awaiter(void 0, void 0, void 0, function* () {
|
|
20
|
-
const MAX_ITERATIONS = 20;
|
|
21
|
-
const WAIT_TIME = 500;
|
|
19
|
+
const waitForStatus = (id, type, maxIterations = 20, wait = 500) => __awaiter(void 0, void 0, void 0, function* () {
|
|
22
20
|
let iterations = 0;
|
|
23
21
|
let status = vsc_1.VscStatus.UNCONFIRMED;
|
|
24
|
-
while (iterations <
|
|
22
|
+
while (iterations < maxIterations) {
|
|
25
23
|
status = yield checkStatus(id, type);
|
|
26
|
-
if (status === vsc_1.VscStatus.
|
|
24
|
+
if (status === vsc_1.VscStatus.CONFIRMED || status === vsc_1.VscStatus.FAILED)
|
|
27
25
|
return status;
|
|
28
26
|
iterations++;
|
|
29
|
-
yield new Promise((resolve) => setTimeout(resolve,
|
|
27
|
+
yield new Promise((resolve) => setTimeout(resolve, wait));
|
|
30
28
|
}
|
|
31
29
|
return status;
|
|
32
30
|
});
|
|
33
31
|
const checkStatus = (id, type) => {
|
|
34
32
|
let query;
|
|
35
|
-
if (type === vsc_1.VscHistoryType.CONTRACT_CALL
|
|
33
|
+
if (type === vsc_1.VscHistoryType.CONTRACT_CALL ||
|
|
34
|
+
type === vsc_1.VscHistoryType.WITHDRAW ||
|
|
35
|
+
type === vsc_1.VscHistoryType.STAKING ||
|
|
36
|
+
type === vsc_1.VscHistoryType.UNSTAKING ||
|
|
37
|
+
type === vsc_1.VscHistoryType.TRANSFER) {
|
|
36
38
|
query = `{
|
|
37
39
|
findTransaction(
|
|
38
|
-
filterOptions: {byId:"${id}
|
|
40
|
+
filterOptions: {byId:"${id}"}
|
|
39
41
|
) {
|
|
40
|
-
txs {
|
|
41
42
|
status
|
|
42
|
-
}
|
|
43
43
|
}
|
|
44
44
|
}`;
|
|
45
45
|
}
|
|
46
|
-
else if (type === vsc_1.VscHistoryType.
|
|
46
|
+
else if (type === vsc_1.VscHistoryType.DEPOSIT) {
|
|
47
47
|
query = `{
|
|
48
48
|
findLedgerTXs(filterOptions: {byTxId: "${id}-0"}) {
|
|
49
|
-
|
|
49
|
+
|
|
50
50
|
status
|
|
51
|
-
|
|
51
|
+
|
|
52
52
|
}
|
|
53
53
|
}`;
|
|
54
54
|
}
|
|
55
55
|
return fetchQuery(query).then((res) => {
|
|
56
|
-
var _a, _b, _c, _d, _e, _f
|
|
57
|
-
|
|
58
|
-
|
|
56
|
+
var _a, _b, _c, _d, _e, _f;
|
|
57
|
+
console.log(res.data);
|
|
58
|
+
return (((_c = (_b = (_a = res === null || res === void 0 ? void 0 : res.data) === null || _a === void 0 ? void 0 : _a.findTransaction) === null || _b === void 0 ? void 0 : _b[0]) === null || _c === void 0 ? void 0 : _c.status) ||
|
|
59
|
+
((_f = (_e = (_d = res === null || res === void 0 ? void 0 : res.data) === null || _d === void 0 ? void 0 : _d.findLedgerTXs) === null || _e === void 0 ? void 0 : _e[0]) === null || _f === void 0 ? void 0 : _f.status));
|
|
59
60
|
});
|
|
60
61
|
};
|
|
61
62
|
const fetchHistory = (username) => __awaiter(void 0, void 0, void 0, function* () {
|