hive-keychain-commons 1.4.3 → 1.5.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/index.d.ts +3 -0
- package/lib/index.js +3 -0
- package/lib/interfaces/keychain.d.ts +1 -1
- package/lib/utils/assets.utils.d.ts +78 -0
- package/lib/utils/assets.utils.js +172 -0
- package/lib/utils/crypto.utils.d.ts +2 -0
- package/lib/utils/crypto.utils.js +58 -0
- package/lib/utils/history-filters.utils.d.ts +96 -0
- package/lib/utils/history-filters.utils.js +120 -0
- package/lib/utils/keys.utils.js +2 -2
- package/lib/utils/transfer.utils.js +2 -2
- package/package.json +9 -1
package/lib/index.d.ts
CHANGED
|
@@ -5,6 +5,9 @@ export { AcceptRequestJSON, CancelDelegationJSON, CancelRequestJSON, PaymentJSON
|
|
|
5
5
|
export * from './swaps/config.interface';
|
|
6
6
|
export * from './swaps/swap-api.interface';
|
|
7
7
|
export * from './swaps/swap.interface';
|
|
8
|
+
export * from './utils/assets.utils';
|
|
9
|
+
export * from './utils/crypto.utils';
|
|
10
|
+
export * from './utils/history-filters.utils';
|
|
8
11
|
export * from './utils/keys.utils';
|
|
9
12
|
export * from './utils/transfer.utils';
|
|
10
13
|
export * from './utils/vsc.utils';
|
package/lib/index.js
CHANGED
|
@@ -22,6 +22,9 @@ Object.defineProperty(exports, "LeaseKeys", { enumerable: true, get: function ()
|
|
|
22
22
|
__exportStar(require("./swaps/config.interface"), exports);
|
|
23
23
|
__exportStar(require("./swaps/swap-api.interface"), exports);
|
|
24
24
|
__exportStar(require("./swaps/swap.interface"), exports);
|
|
25
|
+
__exportStar(require("./utils/assets.utils"), exports);
|
|
26
|
+
__exportStar(require("./utils/crypto.utils"), exports);
|
|
27
|
+
__exportStar(require("./utils/history-filters.utils"), exports);
|
|
25
28
|
__exportStar(require("./utils/keys.utils"), exports);
|
|
26
29
|
__exportStar(require("./utils/transfer.utils"), exports);
|
|
27
30
|
__exportStar(require("./utils/vsc.utils"), exports);
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import type { AssetSymbol, PriceType } from '@hiveio/dhive';
|
|
2
|
+
export declare class Asset {
|
|
3
|
+
amount: number;
|
|
4
|
+
symbol: AssetSymbol;
|
|
5
|
+
constructor(amount: number, symbol: AssetSymbol);
|
|
6
|
+
/**
|
|
7
|
+
* Create a new Asset instance from a string, e.g. `42.000 HIVE`.
|
|
8
|
+
*/
|
|
9
|
+
static fromString: (str: string, expectedSymbol?: AssetSymbol) => Asset;
|
|
10
|
+
/**
|
|
11
|
+
* Convenience to create new Asset.
|
|
12
|
+
* @param symbol Symbol to use when created from number. Will also be used to validate
|
|
13
|
+
* the asset, throws if the passed value has a different symbol than this.
|
|
14
|
+
*/
|
|
15
|
+
static from: (value: number | Asset | string, symbol?: AssetSymbol) => Asset;
|
|
16
|
+
/**
|
|
17
|
+
* Return the smaller of the two assets.
|
|
18
|
+
*/
|
|
19
|
+
static min: (a: Asset, b: Asset) => Asset;
|
|
20
|
+
/**
|
|
21
|
+
* Return the larger of the two assets.
|
|
22
|
+
*/
|
|
23
|
+
static max: (a: Asset, b: Asset) => Asset;
|
|
24
|
+
/**
|
|
25
|
+
* Return asset precision.
|
|
26
|
+
*/
|
|
27
|
+
getPrecision: () => 3 | 6;
|
|
28
|
+
/**
|
|
29
|
+
* Return a string representation of this asset, e.g. `42.000 HIVE`.
|
|
30
|
+
*/
|
|
31
|
+
toString: () => string;
|
|
32
|
+
/**
|
|
33
|
+
* Return a new Asset instance with amount added.
|
|
34
|
+
*/
|
|
35
|
+
add: (amount: number | Asset | string) => Asset;
|
|
36
|
+
/**
|
|
37
|
+
* Return a new Asset instance with amount subtracted.
|
|
38
|
+
*/
|
|
39
|
+
subtract: (amount: number | Asset | string) => Asset;
|
|
40
|
+
/**
|
|
41
|
+
* Return a new Asset with the amount multiplied by factor.
|
|
42
|
+
*/
|
|
43
|
+
multiply: (factor: number | Asset | string) => Asset;
|
|
44
|
+
/**
|
|
45
|
+
* Return a new Asset with the amount divided.
|
|
46
|
+
*/
|
|
47
|
+
divide: (divisor: number | Asset | string) => Asset;
|
|
48
|
+
/**
|
|
49
|
+
* For JSON serialization, same as toString().
|
|
50
|
+
*/
|
|
51
|
+
toJSON: () => string;
|
|
52
|
+
}
|
|
53
|
+
export declare class Price {
|
|
54
|
+
/**
|
|
55
|
+
* @param base - represents a value of the price object to be expressed relatively to quote
|
|
56
|
+
* asset. Cannot have amount == 0 if you want to build valid price.
|
|
57
|
+
* @param quote - represents an relative asset. Cannot have amount == 0, otherwise
|
|
58
|
+
* asertion fail.
|
|
59
|
+
*
|
|
60
|
+
* Both base and quote shall have different symbol defined.
|
|
61
|
+
*/
|
|
62
|
+
base: Asset;
|
|
63
|
+
quote: Asset;
|
|
64
|
+
constructor(base: Asset, quote: Asset);
|
|
65
|
+
/**
|
|
66
|
+
* Convenience to create new Price.
|
|
67
|
+
*/
|
|
68
|
+
static from: (value: PriceType) => Price;
|
|
69
|
+
/**
|
|
70
|
+
* Return a string representation of this price pair.
|
|
71
|
+
*/
|
|
72
|
+
toString: () => string;
|
|
73
|
+
/**
|
|
74
|
+
* Return a new Asset with the price converted between the symbols in the pair.
|
|
75
|
+
* Throws if passed asset symbol is not base or quote.
|
|
76
|
+
*/
|
|
77
|
+
convert: (asset: Asset) => Asset;
|
|
78
|
+
}
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.Price = exports.Asset = void 0;
|
|
7
|
+
const assert_1 = __importDefault(require("assert"));
|
|
8
|
+
class Asset {
|
|
9
|
+
constructor(amount, symbol) {
|
|
10
|
+
/**
|
|
11
|
+
* Return asset precision.
|
|
12
|
+
*/
|
|
13
|
+
this.getPrecision = () => {
|
|
14
|
+
switch (this.symbol) {
|
|
15
|
+
case 'TESTS':
|
|
16
|
+
case 'TBD':
|
|
17
|
+
case 'HIVE':
|
|
18
|
+
case 'HBD':
|
|
19
|
+
case 'SBD':
|
|
20
|
+
case 'STEEM':
|
|
21
|
+
return 3;
|
|
22
|
+
case 'VESTS':
|
|
23
|
+
return 6;
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
/**
|
|
27
|
+
* Return a string representation of this asset, e.g. `42.000 HIVE`.
|
|
28
|
+
*/
|
|
29
|
+
this.toString = () => {
|
|
30
|
+
return this.amount.toFixed(this.getPrecision()) + ' ' + this.symbol;
|
|
31
|
+
};
|
|
32
|
+
/**
|
|
33
|
+
* Return a new Asset instance with amount added.
|
|
34
|
+
*/
|
|
35
|
+
this.add = (amount) => {
|
|
36
|
+
const other = Asset.from(amount, this.symbol);
|
|
37
|
+
(0, assert_1.default)(this.symbol === other.symbol, 'can not add with different symbols');
|
|
38
|
+
return new Asset(this.amount + other.amount, this.symbol);
|
|
39
|
+
};
|
|
40
|
+
/**
|
|
41
|
+
* Return a new Asset instance with amount subtracted.
|
|
42
|
+
*/
|
|
43
|
+
this.subtract = (amount) => {
|
|
44
|
+
const other = Asset.from(amount, this.symbol);
|
|
45
|
+
(0, assert_1.default)(this.symbol === other.symbol, 'can not subtract with different symbols');
|
|
46
|
+
return new Asset(this.amount - other.amount, this.symbol);
|
|
47
|
+
};
|
|
48
|
+
/**
|
|
49
|
+
* Return a new Asset with the amount multiplied by factor.
|
|
50
|
+
*/
|
|
51
|
+
this.multiply = (factor) => {
|
|
52
|
+
const other = Asset.from(factor, this.symbol);
|
|
53
|
+
(0, assert_1.default)(this.symbol === other.symbol, 'can not multiply with different symbols');
|
|
54
|
+
return new Asset(this.amount * other.amount, this.symbol);
|
|
55
|
+
};
|
|
56
|
+
/**
|
|
57
|
+
* Return a new Asset with the amount divided.
|
|
58
|
+
*/
|
|
59
|
+
this.divide = (divisor) => {
|
|
60
|
+
const other = Asset.from(divisor, this.symbol);
|
|
61
|
+
(0, assert_1.default)(this.symbol === other.symbol, 'can not divide with different symbols');
|
|
62
|
+
return new Asset(this.amount / other.amount, this.symbol);
|
|
63
|
+
};
|
|
64
|
+
/**
|
|
65
|
+
* For JSON serialization, same as toString().
|
|
66
|
+
*/
|
|
67
|
+
this.toJSON = () => {
|
|
68
|
+
return this.toString();
|
|
69
|
+
};
|
|
70
|
+
this.amount = amount;
|
|
71
|
+
this.symbol = symbol;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
exports.Asset = Asset;
|
|
75
|
+
/**
|
|
76
|
+
* Create a new Asset instance from a string, e.g. `42.000 HIVE`.
|
|
77
|
+
*/
|
|
78
|
+
Asset.fromString = (str, expectedSymbol) => {
|
|
79
|
+
const _a = str.split(' ');
|
|
80
|
+
const amountString = _a[0];
|
|
81
|
+
const symbol = _a[1];
|
|
82
|
+
if (!['HIVE', 'VESTS', 'HBD', 'TESTS', 'TBD', 'SBD', 'STEEM'].includes(symbol)) {
|
|
83
|
+
throw new Error('Invalid asset symbol: ' + symbol);
|
|
84
|
+
}
|
|
85
|
+
if (expectedSymbol && symbol !== expectedSymbol) {
|
|
86
|
+
throw new Error('Invalid asset, expected symbol: ' + expectedSymbol + ' got: ' + symbol);
|
|
87
|
+
}
|
|
88
|
+
const amount = Number.parseFloat(amountString);
|
|
89
|
+
if (!Number.isFinite(amount)) {
|
|
90
|
+
throw new Error('Invalid asset amount: ' + amountString);
|
|
91
|
+
}
|
|
92
|
+
return new Asset(amount, symbol);
|
|
93
|
+
};
|
|
94
|
+
/**
|
|
95
|
+
* Convenience to create new Asset.
|
|
96
|
+
* @param symbol Symbol to use when created from number. Will also be used to validate
|
|
97
|
+
* the asset, throws if the passed value has a different symbol than this.
|
|
98
|
+
*/
|
|
99
|
+
Asset.from = (value, symbol) => {
|
|
100
|
+
if (value instanceof Asset) {
|
|
101
|
+
if (symbol && value.symbol !== symbol) {
|
|
102
|
+
throw new Error('Invalid asset, expected symbol: ' + symbol + ' got: ' + value.symbol);
|
|
103
|
+
}
|
|
104
|
+
return value;
|
|
105
|
+
}
|
|
106
|
+
else if (typeof value === 'number' && Number.isFinite(value)) {
|
|
107
|
+
return new Asset(value, symbol || 'STEEM');
|
|
108
|
+
}
|
|
109
|
+
else if (typeof value === 'string') {
|
|
110
|
+
return Asset.fromString(value, symbol);
|
|
111
|
+
}
|
|
112
|
+
else {
|
|
113
|
+
throw new Error("Invalid asset '" + String(value) + "'");
|
|
114
|
+
}
|
|
115
|
+
};
|
|
116
|
+
/**
|
|
117
|
+
* Return the smaller of the two assets.
|
|
118
|
+
*/
|
|
119
|
+
Asset.min = (a, b) => {
|
|
120
|
+
(0, assert_1.default)(a.symbol === b.symbol, 'can not compare assets with different symbols');
|
|
121
|
+
return a.amount < b.amount ? a : b;
|
|
122
|
+
};
|
|
123
|
+
/**
|
|
124
|
+
* Return the larger of the two assets.
|
|
125
|
+
*/
|
|
126
|
+
Asset.max = (a, b) => {
|
|
127
|
+
(0, assert_1.default)(a.symbol === b.symbol, 'can not compare assets with different symbols');
|
|
128
|
+
return a.amount > b.amount ? a : b;
|
|
129
|
+
};
|
|
130
|
+
class Price {
|
|
131
|
+
constructor(base, quote) {
|
|
132
|
+
/**
|
|
133
|
+
* Return a string representation of this price pair.
|
|
134
|
+
*/
|
|
135
|
+
this.toString = () => {
|
|
136
|
+
return this.base + ':' + this.quote;
|
|
137
|
+
};
|
|
138
|
+
/**
|
|
139
|
+
* Return a new Asset with the price converted between the symbols in the pair.
|
|
140
|
+
* Throws if passed asset symbol is not base or quote.
|
|
141
|
+
*/
|
|
142
|
+
this.convert = (asset) => {
|
|
143
|
+
if (asset.symbol === this.base.symbol) {
|
|
144
|
+
(0, assert_1.default)(this.base.amount > 0);
|
|
145
|
+
return new Asset((asset.amount * this.quote.amount) / this.base.amount, this.quote.symbol);
|
|
146
|
+
}
|
|
147
|
+
else if (asset.symbol === this.quote.symbol) {
|
|
148
|
+
(0, assert_1.default)(this.quote.amount > 0);
|
|
149
|
+
return new Asset((asset.amount * this.base.amount) / this.quote.amount, this.base.symbol);
|
|
150
|
+
}
|
|
151
|
+
else {
|
|
152
|
+
throw new Error('Can not convert ' + asset + ' with ' + this);
|
|
153
|
+
}
|
|
154
|
+
};
|
|
155
|
+
this.base = base;
|
|
156
|
+
this.quote = quote;
|
|
157
|
+
(0, assert_1.default)(base.amount !== 0 && quote.amount !== 0, 'base and quote assets must be non-zero');
|
|
158
|
+
(0, assert_1.default)(base.symbol !== quote.symbol, 'base and quote can not have the same symbol');
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
exports.Price = Price;
|
|
162
|
+
/**
|
|
163
|
+
* Convenience to create new Price.
|
|
164
|
+
*/
|
|
165
|
+
Price.from = (value) => {
|
|
166
|
+
if (value instanceof Price) {
|
|
167
|
+
return value;
|
|
168
|
+
}
|
|
169
|
+
else {
|
|
170
|
+
return new Price(Asset.from(value.base), Asset.from(value.quote));
|
|
171
|
+
}
|
|
172
|
+
};
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.isWif = void 0;
|
|
27
|
+
const bs58 = __importStar(require("bs58"));
|
|
28
|
+
const crypto_js_1 = require("crypto-js");
|
|
29
|
+
const sha256 = (input) => {
|
|
30
|
+
if (typeof input !== 'string') {
|
|
31
|
+
input = crypto_js_1.lib.WordArray.create(input);
|
|
32
|
+
}
|
|
33
|
+
const hash = Buffer.from((0, crypto_js_1.SHA256)(input).toString(CryptoJS.enc.Hex), 'hex');
|
|
34
|
+
return hash;
|
|
35
|
+
};
|
|
36
|
+
const ripemd160 = (input) => {
|
|
37
|
+
// return crypto.createHash('ripemd160').update(input).digest()
|
|
38
|
+
if (typeof input !== 'string') {
|
|
39
|
+
input = CryptoJS.lib.WordArray.create(input);
|
|
40
|
+
}
|
|
41
|
+
const hash = Buffer.from((0, crypto_js_1.RIPEMD160)(input).toString(CryptoJS.enc.Hex), 'hex');
|
|
42
|
+
return hash;
|
|
43
|
+
};
|
|
44
|
+
const isWif = (privWif) => {
|
|
45
|
+
try {
|
|
46
|
+
const bufWif = new Buffer(bs58.decode(privWif));
|
|
47
|
+
const privKey = bufWif.slice(0, -4);
|
|
48
|
+
const checksum = bufWif.slice(-4);
|
|
49
|
+
let newChecksum = sha256(privKey);
|
|
50
|
+
newChecksum = sha256(newChecksum);
|
|
51
|
+
newChecksum = newChecksum.slice(0, 4);
|
|
52
|
+
return checksum.toString() === newChecksum.toString();
|
|
53
|
+
}
|
|
54
|
+
catch (e) {
|
|
55
|
+
return false;
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
exports.isWif = isWif;
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Make bitmask filter to be used with getAccountHistory call
|
|
3
|
+
* @param allowedOperations Array of operations index numbers
|
|
4
|
+
*/
|
|
5
|
+
declare function makeBitMaskFilter(allowedOperations: number[]): any;
|
|
6
|
+
export declare const HistoryFiltersUtils: {
|
|
7
|
+
operationOrders: {
|
|
8
|
+
vote: number;
|
|
9
|
+
comment: number;
|
|
10
|
+
transfer: number;
|
|
11
|
+
transfer_to_vesting: number;
|
|
12
|
+
withdraw_vesting: number;
|
|
13
|
+
limit_order_create: number;
|
|
14
|
+
limit_order_cancel: number;
|
|
15
|
+
feed_publish: number;
|
|
16
|
+
convert: number;
|
|
17
|
+
account_create: number;
|
|
18
|
+
account_update: number;
|
|
19
|
+
witness_update: number;
|
|
20
|
+
account_witness_vote: number;
|
|
21
|
+
account_witness_proxy: number;
|
|
22
|
+
pow: number;
|
|
23
|
+
custom: number;
|
|
24
|
+
report_over_production: number;
|
|
25
|
+
delete_comment: number;
|
|
26
|
+
custom_json: number;
|
|
27
|
+
comment_options: number;
|
|
28
|
+
set_withdraw_vesting_route: number;
|
|
29
|
+
limit_order_create2: number;
|
|
30
|
+
claim_account: number;
|
|
31
|
+
create_claimed_account: number;
|
|
32
|
+
request_account_recovery: number;
|
|
33
|
+
recover_account: number;
|
|
34
|
+
change_recovery_account: number;
|
|
35
|
+
escrow_transfer: number;
|
|
36
|
+
escrow_dispute: number;
|
|
37
|
+
escrow_release: number;
|
|
38
|
+
pow2: number;
|
|
39
|
+
escrow_approve: number;
|
|
40
|
+
transfer_to_savings: number;
|
|
41
|
+
transfer_from_savings: number;
|
|
42
|
+
cancel_transfer_from_savings: number;
|
|
43
|
+
custom_binary: number;
|
|
44
|
+
decline_voting_rights: number;
|
|
45
|
+
reset_account: number;
|
|
46
|
+
set_reset_account: number;
|
|
47
|
+
claim_reward_balance: number;
|
|
48
|
+
delegate_vesting_shares: number;
|
|
49
|
+
account_create_with_delegation: number;
|
|
50
|
+
witness_set_properties: number;
|
|
51
|
+
account_update2: number;
|
|
52
|
+
create_proposal: number;
|
|
53
|
+
update_proposal_votes: number;
|
|
54
|
+
remove_proposal: number;
|
|
55
|
+
update_proposal: number;
|
|
56
|
+
collateralized_convert: number;
|
|
57
|
+
recurrent_transfer: number;
|
|
58
|
+
fill_convert_request: number;
|
|
59
|
+
author_reward: number;
|
|
60
|
+
curation_reward: number;
|
|
61
|
+
comment_reward: number;
|
|
62
|
+
liquidity_reward: number;
|
|
63
|
+
interest: number;
|
|
64
|
+
fill_vesting_withdraw: number;
|
|
65
|
+
fill_order: number;
|
|
66
|
+
shutdown_witness: number;
|
|
67
|
+
fill_transfer_from_savings: number;
|
|
68
|
+
hardfork: number;
|
|
69
|
+
comment_payout_update: number;
|
|
70
|
+
return_vesting_delegation: number;
|
|
71
|
+
comment_benefactor_reward: number;
|
|
72
|
+
producer_reward: number;
|
|
73
|
+
clear_null_account_balance: number;
|
|
74
|
+
proposal_pay: number;
|
|
75
|
+
sps_fund: number;
|
|
76
|
+
hardfork_hive: number;
|
|
77
|
+
hardfork_hive_restore: number;
|
|
78
|
+
delayed_voting: number;
|
|
79
|
+
consolidate_treasury_balance: number;
|
|
80
|
+
effective_comment_vote: number;
|
|
81
|
+
ineffective_delete_comment: number;
|
|
82
|
+
sps_convert: number;
|
|
83
|
+
expired_account_notification: number;
|
|
84
|
+
changed_recovery_account: number;
|
|
85
|
+
transfer_to_vesting_completed: number;
|
|
86
|
+
pow_reward: number;
|
|
87
|
+
vesting_shares_split: number;
|
|
88
|
+
account_created: number;
|
|
89
|
+
fill_collateralized_convert_request: number;
|
|
90
|
+
system_warning: number;
|
|
91
|
+
fill_recurrent_transfer: number;
|
|
92
|
+
failed_recurrent_transfer: number;
|
|
93
|
+
};
|
|
94
|
+
makeBitMaskFilter: typeof makeBitMaskFilter;
|
|
95
|
+
};
|
|
96
|
+
export {};
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.HistoryFiltersUtils = void 0;
|
|
7
|
+
const jsbi_1 = __importDefault(require("jsbi"));
|
|
8
|
+
const operationOrders = {
|
|
9
|
+
vote: 0,
|
|
10
|
+
// tslint:disable-next-line: object-literal-sort-keys
|
|
11
|
+
comment: 1,
|
|
12
|
+
transfer: 2,
|
|
13
|
+
transfer_to_vesting: 3,
|
|
14
|
+
withdraw_vesting: 4,
|
|
15
|
+
limit_order_create: 5,
|
|
16
|
+
limit_order_cancel: 6,
|
|
17
|
+
feed_publish: 7,
|
|
18
|
+
convert: 8,
|
|
19
|
+
account_create: 9,
|
|
20
|
+
account_update: 10,
|
|
21
|
+
witness_update: 11,
|
|
22
|
+
account_witness_vote: 12,
|
|
23
|
+
account_witness_proxy: 13,
|
|
24
|
+
pow: 14,
|
|
25
|
+
custom: 15,
|
|
26
|
+
report_over_production: 16,
|
|
27
|
+
delete_comment: 17,
|
|
28
|
+
custom_json: 18,
|
|
29
|
+
comment_options: 19,
|
|
30
|
+
set_withdraw_vesting_route: 20,
|
|
31
|
+
limit_order_create2: 21,
|
|
32
|
+
claim_account: 22,
|
|
33
|
+
create_claimed_account: 23,
|
|
34
|
+
request_account_recovery: 24,
|
|
35
|
+
recover_account: 25,
|
|
36
|
+
change_recovery_account: 26,
|
|
37
|
+
escrow_transfer: 27,
|
|
38
|
+
escrow_dispute: 28,
|
|
39
|
+
escrow_release: 29,
|
|
40
|
+
pow2: 30,
|
|
41
|
+
escrow_approve: 31,
|
|
42
|
+
transfer_to_savings: 32,
|
|
43
|
+
transfer_from_savings: 33,
|
|
44
|
+
cancel_transfer_from_savings: 34,
|
|
45
|
+
custom_binary: 35,
|
|
46
|
+
decline_voting_rights: 36,
|
|
47
|
+
reset_account: 37,
|
|
48
|
+
set_reset_account: 38,
|
|
49
|
+
claim_reward_balance: 39,
|
|
50
|
+
delegate_vesting_shares: 40,
|
|
51
|
+
account_create_with_delegation: 41,
|
|
52
|
+
witness_set_properties: 42,
|
|
53
|
+
account_update2: 43,
|
|
54
|
+
create_proposal: 44,
|
|
55
|
+
update_proposal_votes: 45,
|
|
56
|
+
remove_proposal: 46,
|
|
57
|
+
update_proposal: 47,
|
|
58
|
+
collateralized_convert: 48,
|
|
59
|
+
recurrent_transfer: 49,
|
|
60
|
+
// virtual ops
|
|
61
|
+
fill_convert_request: 50,
|
|
62
|
+
author_reward: 51,
|
|
63
|
+
curation_reward: 52,
|
|
64
|
+
comment_reward: 53,
|
|
65
|
+
liquidity_reward: 54,
|
|
66
|
+
interest: 55,
|
|
67
|
+
fill_vesting_withdraw: 56,
|
|
68
|
+
fill_order: 57,
|
|
69
|
+
shutdown_witness: 58,
|
|
70
|
+
fill_transfer_from_savings: 59,
|
|
71
|
+
hardfork: 60,
|
|
72
|
+
comment_payout_update: 61,
|
|
73
|
+
return_vesting_delegation: 62,
|
|
74
|
+
comment_benefactor_reward: 63,
|
|
75
|
+
producer_reward: 64,
|
|
76
|
+
clear_null_account_balance: 65,
|
|
77
|
+
proposal_pay: 66,
|
|
78
|
+
sps_fund: 67,
|
|
79
|
+
hardfork_hive: 68,
|
|
80
|
+
hardfork_hive_restore: 69,
|
|
81
|
+
delayed_voting: 70,
|
|
82
|
+
consolidate_treasury_balance: 71,
|
|
83
|
+
effective_comment_vote: 72,
|
|
84
|
+
ineffective_delete_comment: 73,
|
|
85
|
+
sps_convert: 74,
|
|
86
|
+
expired_account_notification: 75,
|
|
87
|
+
changed_recovery_account: 76,
|
|
88
|
+
transfer_to_vesting_completed: 77,
|
|
89
|
+
pow_reward: 78,
|
|
90
|
+
vesting_shares_split: 79,
|
|
91
|
+
account_created: 80,
|
|
92
|
+
fill_collateralized_convert_request: 81,
|
|
93
|
+
system_warning: 82,
|
|
94
|
+
fill_recurrent_transfer: 83,
|
|
95
|
+
failed_recurrent_transfer: 84,
|
|
96
|
+
};
|
|
97
|
+
/**
|
|
98
|
+
* Make bitmask filter to be used with getAccountHistory call
|
|
99
|
+
* @param allowedOperations Array of operations index numbers
|
|
100
|
+
*/
|
|
101
|
+
function makeBitMaskFilter(allowedOperations) {
|
|
102
|
+
return allowedOperations
|
|
103
|
+
.map((value) => jsbi_1.default.notEqual(value, jsbi_1.default.BigInt(0)) ? value.toString() : null)
|
|
104
|
+
.reduce(redFunction, [jsbi_1.default.BigInt(0), jsbi_1.default.BigInt(0)]);
|
|
105
|
+
}
|
|
106
|
+
const redFunction = ([low, high], allowedOperation) => {
|
|
107
|
+
if (allowedOperation < 64) {
|
|
108
|
+
return [
|
|
109
|
+
jsbi_1.default.bitwiseOr(low, jsbi_1.default.leftShift(jsbi_1.default.BigInt(1), jsbi_1.default.BigInt(allowedOperation))),
|
|
110
|
+
high,
|
|
111
|
+
];
|
|
112
|
+
}
|
|
113
|
+
else {
|
|
114
|
+
return [
|
|
115
|
+
low,
|
|
116
|
+
jsbi_1.default.bitwiseOr(high, jsbi_1.default.leftShift(jsbi_1.default.BigInt(1), jsbi_1.default.BigInt(allowedOperation - 64))),
|
|
117
|
+
];
|
|
118
|
+
}
|
|
119
|
+
};
|
|
120
|
+
exports.HistoryFiltersUtils = { operationOrders, makeBitMaskFilter };
|
package/lib/utils/keys.utils.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getPublicKeyFromPrivateKeyString = void 0;
|
|
4
|
-
const
|
|
4
|
+
const hive_tx_1 = require("hive-tx");
|
|
5
5
|
const getPublicKeyFromPrivateKeyString = (privateKeyS) => {
|
|
6
6
|
try {
|
|
7
|
-
const privateKey =
|
|
7
|
+
const privateKey = hive_tx_1.PrivateKey.fromString(privateKeyS);
|
|
8
8
|
const publicKey = privateKey.createPublic();
|
|
9
9
|
return publicKey.toString();
|
|
10
10
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getPrivateKeysMemoValidationWarning = void 0;
|
|
4
|
-
const
|
|
4
|
+
const crypto_utils_1 = require("./crypto.utils");
|
|
5
5
|
const keys_utils_1 = require("./keys.utils");
|
|
6
6
|
const getPrivateKeysMemoValidationWarning = (memo) => {
|
|
7
7
|
const memoTemp = memo.startsWith('#')
|
|
@@ -11,7 +11,7 @@ const getPrivateKeysMemoValidationWarning = (memo) => {
|
|
|
11
11
|
found = memoTemp.match(/[\w\d]{51,52}/g);
|
|
12
12
|
if (found) {
|
|
13
13
|
for (const word of found) {
|
|
14
|
-
if (
|
|
14
|
+
if ((0, crypto_utils_1.isWif)(word) && word.length === 51) {
|
|
15
15
|
if ((0, keys_utils_1.getPublicKeyFromPrivateKeyString)(word))
|
|
16
16
|
return true;
|
|
17
17
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "hive-keychain-commons",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.5.0",
|
|
4
4
|
"description": "Platform-agnostic functions used in Hive Keychain mobile and extensions",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"types": "lib/index.d.ts",
|
|
@@ -36,8 +36,11 @@
|
|
|
36
36
|
},
|
|
37
37
|
"homepage": "https://github.com/stoodkev/hive-keychain-commons#readme",
|
|
38
38
|
"devDependencies": {
|
|
39
|
+
"@types/bs58": "^4.0.4",
|
|
39
40
|
"@types/bytebuffer": "^5.0.44",
|
|
41
|
+
"@types/crypto-js": "^4.2.2",
|
|
40
42
|
"@types/node": "^18.11.19",
|
|
43
|
+
"@types/secp256k1": "^4.0.6",
|
|
41
44
|
"prettier": "^2.4.1",
|
|
42
45
|
"tslint": "^6.1.3",
|
|
43
46
|
"tslint-config-prettier": "^1.18.0",
|
|
@@ -45,7 +48,12 @@
|
|
|
45
48
|
},
|
|
46
49
|
"dependencies": {
|
|
47
50
|
"@hiveio/dhive": "^1.2.8",
|
|
51
|
+
"bs58": "^4.0.1",
|
|
52
|
+
"crypto-js": "^4.2.0",
|
|
53
|
+
"hive-tx": "^6.0.4",
|
|
54
|
+
"jsbi": "^4.3.0",
|
|
48
55
|
"moment": "^2.30.1",
|
|
56
|
+
"secp256k1": "^5.0.1",
|
|
49
57
|
"winston": "^3.8.1",
|
|
50
58
|
"winston-daily-rotate-file": "^4.7.1"
|
|
51
59
|
}
|