@ledgerhq/coin-polkadot 0.0.2
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/.eslintrc.js +57 -0
- package/.turbo/turbo-build.log +4 -0
- package/CHANGELOG.md +12 -0
- package/jest.config.js +10 -0
- package/lib/account.d.ts +15 -0
- package/lib/account.d.ts.map +1 -0
- package/lib/account.js +133 -0
- package/lib/account.js.map +1 -0
- package/lib/address.d.ts +7 -0
- package/lib/address.d.ts.map +1 -0
- package/lib/address.js +28 -0
- package/lib/address.js.map +1 -0
- package/lib/api/bisontrails.d.ts +11 -0
- package/lib/api/bisontrails.d.ts.map +1 -0
- package/lib/api/bisontrails.js +351 -0
- package/lib/api/bisontrails.js.map +1 -0
- package/lib/api/common.d.ts +12 -0
- package/lib/api/common.d.ts.map +1 -0
- package/lib/api/common.js +41 -0
- package/lib/api/common.js.map +1 -0
- package/lib/api/index.d.ts +3 -0
- package/lib/api/index.d.ts.map +1 -0
- package/lib/api/index.js +53 -0
- package/lib/api/index.js.map +1 -0
- package/lib/api/sidecar.d.ts +193 -0
- package/lib/api/sidecar.d.ts.map +1 -0
- package/lib/api/sidecar.js +844 -0
- package/lib/api/sidecar.js.map +1 -0
- package/lib/api/sidecar.types.d.ts +163 -0
- package/lib/api/sidecar.types.d.ts.map +1 -0
- package/lib/api/sidecar.types.js +3 -0
- package/lib/api/sidecar.types.js.map +1 -0
- package/lib/api/subscan.d.ts +6 -0
- package/lib/api/subscan.d.ts.map +1 -0
- package/lib/api/subscan.js +375 -0
- package/lib/api/subscan.js.map +1 -0
- package/lib/api/websocket.d.ts +92 -0
- package/lib/api/websocket.d.ts.map +1 -0
- package/lib/api/websocket.js +759 -0
- package/lib/api/websocket.js.map +1 -0
- package/lib/bridge/js.d.ts +6 -0
- package/lib/bridge/js.d.ts.map +1 -0
- package/lib/bridge/js.js +120 -0
- package/lib/bridge/js.js.map +1 -0
- package/lib/bridge.integration.test.d.ts +4 -0
- package/lib/bridge.integration.test.d.ts.map +1 -0
- package/lib/bridge.integration.test.js +795 -0
- package/lib/bridge.integration.test.js.map +1 -0
- package/lib/cache.d.ts +65 -0
- package/lib/cache.d.ts.map +1 -0
- package/lib/cache.js +182 -0
- package/lib/cache.js.map +1 -0
- package/lib/cli-transaction.d.ts +44 -0
- package/lib/cli-transaction.d.ts.map +1 -0
- package/lib/cli-transaction.js +148 -0
- package/lib/cli-transaction.js.map +1 -0
- package/lib/deviceTransactionConfig.d.ts +16 -0
- package/lib/deviceTransactionConfig.d.ts.map +1 -0
- package/lib/deviceTransactionConfig.js +171 -0
- package/lib/deviceTransactionConfig.js.map +1 -0
- package/lib/errors.d.ts +37 -0
- package/lib/errors.d.ts.map +1 -0
- package/lib/errors.js +17 -0
- package/lib/errors.js.map +1 -0
- package/lib/hw-getAddress.d.ts +4 -0
- package/lib/hw-getAddress.d.ts.map +1 -0
- package/lib/hw-getAddress.js +64 -0
- package/lib/hw-getAddress.js.map +1 -0
- package/lib/js-buildTransaction.d.ts +25 -0
- package/lib/js-buildTransaction.d.ts.map +1 -0
- package/lib/js-buildTransaction.js +265 -0
- package/lib/js-buildTransaction.js.map +1 -0
- package/lib/js-createTransaction.d.ts +9 -0
- package/lib/js-createTransaction.d.ts.map +1 -0
- package/lib/js-createTransaction.js +22 -0
- package/lib/js-createTransaction.js.map +1 -0
- package/lib/js-estimateMaxSpendable.d.ts +15 -0
- package/lib/js-estimateMaxSpendable.d.ts.map +1 -0
- package/lib/js-estimateMaxSpendable.js +89 -0
- package/lib/js-estimateMaxSpendable.js.map +1 -0
- package/lib/js-getFeesForTransaction.d.ts +14 -0
- package/lib/js-getFeesForTransaction.d.ts.map +1 -0
- package/lib/js-getFeesForTransaction.js +94 -0
- package/lib/js-getFeesForTransaction.js.map +1 -0
- package/lib/js-getTransactionStatus.d.ts +18 -0
- package/lib/js-getTransactionStatus.d.ts.map +1 -0
- package/lib/js-getTransactionStatus.js +316 -0
- package/lib/js-getTransactionStatus.js.map +1 -0
- package/lib/js-prepareTransaction.d.ts +9 -0
- package/lib/js-prepareTransaction.d.ts.map +1 -0
- package/lib/js-prepareTransaction.js +83 -0
- package/lib/js-prepareTransaction.js.map +1 -0
- package/lib/js-signOperation.d.ts +27 -0
- package/lib/js-signOperation.d.ts.map +1 -0
- package/lib/js-signOperation.js +235 -0
- package/lib/js-signOperation.js.map +1 -0
- package/lib/js-synchronisation.d.ts +3 -0
- package/lib/js-synchronisation.d.ts.map +1 -0
- package/lib/js-synchronisation.js +104 -0
- package/lib/js-synchronisation.js.map +1 -0
- package/lib/logic.d.ts +107 -0
- package/lib/logic.d.ts.map +1 -0
- package/lib/logic.js +242 -0
- package/lib/logic.js.map +1 -0
- package/lib/platformAdapter.d.ts +11 -0
- package/lib/platformAdapter.d.ts.map +1 -0
- package/lib/platformAdapter.js +25 -0
- package/lib/platformAdapter.js.map +1 -0
- package/lib/platformAdapter.test.d.ts +2 -0
- package/lib/platformAdapter.test.d.ts.map +1 -0
- package/lib/platformAdapter.test.js +51 -0
- package/lib/platformAdapter.test.js.map +1 -0
- package/lib/polkadot-crypto.d.ts +2 -0
- package/lib/polkadot-crypto.d.ts.map +1 -0
- package/lib/polkadot-crypto.js +14 -0
- package/lib/polkadot-crypto.js.map +1 -0
- package/lib/preload.d.ts +14 -0
- package/lib/preload.d.ts.map +1 -0
- package/lib/preload.js +173 -0
- package/lib/preload.js.map +1 -0
- package/lib/serialization.d.ts +4 -0
- package/lib/serialization.d.ts.map +1 -0
- package/lib/serialization.js +51 -0
- package/lib/serialization.js.map +1 -0
- package/lib/specs.d.ts +7 -0
- package/lib/specs.d.ts.map +1 -0
- package/lib/specs.js +274 -0
- package/lib/specs.js.map +1 -0
- package/lib/speculos-deviceActions.d.ts +4 -0
- package/lib/speculos-deviceActions.d.ts.map +1 -0
- package/lib/speculos-deviceActions.js +85 -0
- package/lib/speculos-deviceActions.js.map +1 -0
- package/lib/transaction.d.ts +15 -0
- package/lib/transaction.d.ts.map +1 -0
- package/lib/transaction.js +51 -0
- package/lib/transaction.js.map +1 -0
- package/lib/types.d.ts +96 -0
- package/lib/types.d.ts.map +1 -0
- package/lib/types.js +3 -0
- package/lib/types.js.map +1 -0
- package/lib/validators.d.ts +3 -0
- package/lib/validators.d.ts.map +1 -0
- package/lib/validators.js +7 -0
- package/lib/validators.js.map +1 -0
- package/package.json +95 -0
- package/src/account.ts +170 -0
- package/src/address.ts +28 -0
- package/src/api/bisontrails.ts +343 -0
- package/src/api/common.ts +52 -0
- package/src/api/index.ts +38 -0
- package/src/api/sidecar.ts +735 -0
- package/src/api/sidecar.types.ts +162 -0
- package/src/api/subscan.ts +362 -0
- package/src/api/websocket.ts +535 -0
- package/src/bridge/js.ts +81 -0
- package/src/bridge.integration.test.ts +764 -0
- package/src/cache.ts +202 -0
- package/src/cli-transaction.ts +184 -0
- package/src/deviceTransactionConfig.ts +209 -0
- package/src/errors.ts +39 -0
- package/src/hw-getAddress.ts +14 -0
- package/src/js-buildTransaction.ts +206 -0
- package/src/js-createTransaction.ts +22 -0
- package/src/js-estimateMaxSpendable.ts +37 -0
- package/src/js-getFeesForTransaction.ts +41 -0
- package/src/js-getTransactionStatus.ts +350 -0
- package/src/js-prepareTransaction.ts +27 -0
- package/src/js-signOperation.ts +232 -0
- package/src/js-synchronisation.ts +57 -0
- package/src/logic.ts +266 -0
- package/src/platformAdapter.test.ts +61 -0
- package/src/platformAdapter.ts +29 -0
- package/src/polkadot-crypto.ts +10 -0
- package/src/preload.ts +148 -0
- package/src/serialization.ts +48 -0
- package/src/specs.ts +305 -0
- package/src/speculos-deviceActions.ts +84 -0
- package/src/transaction.ts +64 -0
- package/src/types.ts +118 -0
- package/src/validators.ts +2 -0
- package/tsconfig.json +21 -0
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __assign = (this && this.__assign) || function () {
|
|
3
|
+
__assign = Object.assign || function(t) {
|
|
4
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
+
s = arguments[i];
|
|
6
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
+
t[p] = s[p];
|
|
8
|
+
}
|
|
9
|
+
return t;
|
|
10
|
+
};
|
|
11
|
+
return __assign.apply(this, arguments);
|
|
12
|
+
};
|
|
13
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
14
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
15
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
16
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
17
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
18
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
19
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
20
|
+
});
|
|
21
|
+
};
|
|
22
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
23
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
24
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
25
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
26
|
+
function step(op) {
|
|
27
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
28
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
29
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
30
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
31
|
+
switch (op[0]) {
|
|
32
|
+
case 0: case 1: t = op; break;
|
|
33
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
34
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
35
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
36
|
+
default:
|
|
37
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
38
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
39
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
40
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
41
|
+
if (t[2]) _.ops.pop();
|
|
42
|
+
_.trys.pop(); continue;
|
|
43
|
+
}
|
|
44
|
+
op = body.call(thisArg, _);
|
|
45
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
46
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
50
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
51
|
+
};
|
|
52
|
+
exports.__esModule = true;
|
|
53
|
+
var js_getFeesForTransaction_1 = __importDefault(require("./js-getFeesForTransaction"));
|
|
54
|
+
var polkadot_crypto_1 = require("./polkadot-crypto");
|
|
55
|
+
var sameFees = function (a, b) { return (!a || !b ? a === b : a.eq(b)); };
|
|
56
|
+
/**
|
|
57
|
+
* Calculate fees for the current transaction
|
|
58
|
+
* @param {PolkadotAccount} a
|
|
59
|
+
* @param {Transaction} t
|
|
60
|
+
*/
|
|
61
|
+
var prepareTransaction = function (a, t) { return __awaiter(void 0, void 0, void 0, function () {
|
|
62
|
+
var fees;
|
|
63
|
+
return __generator(this, function (_a) {
|
|
64
|
+
switch (_a.label) {
|
|
65
|
+
case 0: return [4 /*yield*/, (0, polkadot_crypto_1.loadPolkadotCrypto)()];
|
|
66
|
+
case 1:
|
|
67
|
+
_a.sent();
|
|
68
|
+
fees = t.fees;
|
|
69
|
+
return [4 /*yield*/, (0, js_getFeesForTransaction_1["default"])({
|
|
70
|
+
a: a,
|
|
71
|
+
t: t
|
|
72
|
+
})];
|
|
73
|
+
case 2:
|
|
74
|
+
fees = _a.sent();
|
|
75
|
+
if (!sameFees(t.fees, fees)) {
|
|
76
|
+
return [2 /*return*/, __assign(__assign({}, t), { fees: fees })];
|
|
77
|
+
}
|
|
78
|
+
return [2 /*return*/, t];
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
|
+
}); };
|
|
82
|
+
exports["default"] = prepareTransaction;
|
|
83
|
+
//# sourceMappingURL=js-prepareTransaction.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"js-prepareTransaction.js","sourceRoot":"","sources":["../src/js-prepareTransaction.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,wFAA0D;AAC1D,qDAAuD;AAEvD,IAAM,QAAQ,GAAG,UAAC,CAAC,EAAE,CAAC,IAAK,OAAA,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,EAA9B,CAA8B,CAAC;AAE1D;;;;GAIG;AACH,IAAM,kBAAkB,GAAG,UAAO,CAAkB,EAAE,CAAc;;;;oBAClE,qBAAM,IAAA,oCAAkB,GAAE,EAAA;;gBAA1B,SAA0B,CAAC;gBACvB,IAAI,GAAG,CAAC,CAAC,IAAI,CAAC;gBACX,qBAAM,IAAA,qCAAgB,EAAC;wBAC5B,CAAC,GAAA;wBACD,CAAC,GAAA;qBACF,CAAC,EAAA;;gBAHF,IAAI,GAAG,SAGL,CAAC;gBAEH,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,EAAE,IAAI,CAAC,EAAE;oBAC3B,4CAAY,CAAC,KAAE,IAAI,MAAA,KAAG;iBACvB;gBAED,sBAAO,CAAC,EAAC;;;KACV,CAAC;AAEF,qBAAe,kBAAkB,CAAC"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { TypeRegistry } from "@polkadot/types";
|
|
2
|
+
import type { Transaction } from "./types";
|
|
3
|
+
import type { SignOperationFnSignature } from "@ledgerhq/types-live";
|
|
4
|
+
import { DeviceCommunication } from "@ledgerhq/coin-framework/bridge/jsHelpers";
|
|
5
|
+
/**
|
|
6
|
+
* Serialize a signed transaction in a format that can be submitted over the
|
|
7
|
+
* Node RPC Interface from the signing payload and signature produced by the
|
|
8
|
+
* remote signer.
|
|
9
|
+
*
|
|
10
|
+
* @param unsigned - The JSON representing the unsigned transaction.
|
|
11
|
+
* @param signature - Signature of the signing payload produced by the remote signer.
|
|
12
|
+
* @param registry - Registry used for constructing the payload.
|
|
13
|
+
*/
|
|
14
|
+
export declare const signExtrinsic: (unsigned: Record<string, any>, signature: any, registry: TypeRegistry) => Promise<string>;
|
|
15
|
+
/**
|
|
16
|
+
* Sign Extrinsic with a fake signature (for fees estimation).
|
|
17
|
+
*
|
|
18
|
+
* @param unsigned - The JSON representing the unsigned transaction.
|
|
19
|
+
* @param registry - Registry used for constructing the payload.
|
|
20
|
+
*/
|
|
21
|
+
export declare const fakeSignExtrinsic: (unsigned: Record<string, any>, registry: TypeRegistry) => Promise<string>;
|
|
22
|
+
/**
|
|
23
|
+
* Sign Transaction with Ledger hardware
|
|
24
|
+
*/
|
|
25
|
+
declare const buildSignOperation: (withDevice: DeviceCommunication) => SignOperationFnSignature<Transaction>;
|
|
26
|
+
export default buildSignOperation;
|
|
27
|
+
//# sourceMappingURL=js-signOperation.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"js-signOperation.d.ts","sourceRoot":"","sources":["../src/js-signOperation.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAI/C,OAAO,KAAK,EAAmB,WAAW,EAAE,MAAM,SAAS,CAAC;AAC5D,OAAO,KAAK,EAKV,wBAAwB,EACzB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,mBAAmB,EAAE,MAAM,2CAA2C,CAAC;AAoGhF;;;;;;;;GAQG;AACH,eAAO,MAAM,aAAa,aACd,OAAO,MAAM,EAAE,GAAG,CAAC,aAClB,GAAG,YACJ,YAAY,KACrB,QAAQ,MAAM,CAMhB,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,iBAAiB,aAClB,OAAO,MAAM,EAAE,GAAG,CAAC,YACnB,YAAY,KACrB,QAAQ,MAAM,CAMhB,CAAC;AAEF;;GAEG;AACH,QAAA,MAAM,kBAAkB,eACT,mBAAmB,KAAG,yBAAyB,WAAW,CAyEpE,CAAC;AAEN,eAAe,kBAAkB,CAAC"}
|
|
@@ -0,0 +1,235 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __assign = (this && this.__assign) || function () {
|
|
3
|
+
__assign = Object.assign || function(t) {
|
|
4
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
+
s = arguments[i];
|
|
6
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
+
t[p] = s[p];
|
|
8
|
+
}
|
|
9
|
+
return t;
|
|
10
|
+
};
|
|
11
|
+
return __assign.apply(this, arguments);
|
|
12
|
+
};
|
|
13
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
14
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
15
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
16
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
17
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
18
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
19
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
20
|
+
});
|
|
21
|
+
};
|
|
22
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
23
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
24
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
25
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
26
|
+
function step(op) {
|
|
27
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
28
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
29
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
30
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
31
|
+
switch (op[0]) {
|
|
32
|
+
case 0: case 1: t = op; break;
|
|
33
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
34
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
35
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
36
|
+
default:
|
|
37
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
38
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
39
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
40
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
41
|
+
if (t[2]) _.ops.pop();
|
|
42
|
+
_.trys.pop(); continue;
|
|
43
|
+
}
|
|
44
|
+
op = body.call(thisArg, _);
|
|
45
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
46
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
50
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
51
|
+
};
|
|
52
|
+
exports.__esModule = true;
|
|
53
|
+
exports.fakeSignExtrinsic = exports.signExtrinsic = void 0;
|
|
54
|
+
var bignumber_js_1 = require("bignumber.js");
|
|
55
|
+
var rxjs_1 = require("rxjs");
|
|
56
|
+
var util_1 = require("@polkadot/util");
|
|
57
|
+
var errors_1 = require("@ledgerhq/errors");
|
|
58
|
+
var hw_app_polkadot_1 = __importDefault(require("@ledgerhq/hw-app-polkadot"));
|
|
59
|
+
var operation_1 = require("@ledgerhq/coin-framework/operation");
|
|
60
|
+
var js_buildTransaction_1 = require("./js-buildTransaction");
|
|
61
|
+
var logic_1 = require("./logic");
|
|
62
|
+
var MODE_TO_TYPE = {
|
|
63
|
+
send: "OUT",
|
|
64
|
+
bond: "BOND",
|
|
65
|
+
unbond: "UNBOND",
|
|
66
|
+
rebond: "BOND",
|
|
67
|
+
withdrawUnbonded: "WITHDRAW_UNBONDED",
|
|
68
|
+
nominate: "NOMINATE",
|
|
69
|
+
chill: "CHILL",
|
|
70
|
+
setController: "SET_CONTROLLER",
|
|
71
|
+
claimReward: "REWARD_PAYOUT",
|
|
72
|
+
"default": "FEES"
|
|
73
|
+
};
|
|
74
|
+
var MODE_TO_PALLET_METHOD = {
|
|
75
|
+
send: "balances.transferKeepAlive",
|
|
76
|
+
sendMax: "balances.transfer",
|
|
77
|
+
bond: "staking.bond",
|
|
78
|
+
bondExtra: "staking.bondExtra",
|
|
79
|
+
unbond: "staking.unbond",
|
|
80
|
+
rebond: "staking.rebond",
|
|
81
|
+
withdrawUnbonded: "staking.withdrawUnbonded",
|
|
82
|
+
nominate: "staking.nominate",
|
|
83
|
+
chill: "staking.chill",
|
|
84
|
+
setController: "staking.setController",
|
|
85
|
+
claimReward: "staking.payoutStakers"
|
|
86
|
+
};
|
|
87
|
+
var getExtra = function (type, account, transaction) {
|
|
88
|
+
var _a;
|
|
89
|
+
var extra = {
|
|
90
|
+
palletMethod: MODE_TO_PALLET_METHOD[transaction.mode]
|
|
91
|
+
};
|
|
92
|
+
if (transaction.mode == "send" && transaction.useAllAmount) {
|
|
93
|
+
extra.palletMethod = MODE_TO_PALLET_METHOD["sendMax"];
|
|
94
|
+
}
|
|
95
|
+
else if (transaction.mode === "bond" && !(0, logic_1.isFirstBond)(account)) {
|
|
96
|
+
extra.palletMethod = MODE_TO_PALLET_METHOD["bondExtra"];
|
|
97
|
+
}
|
|
98
|
+
switch (type) {
|
|
99
|
+
case "OUT":
|
|
100
|
+
return __assign(__assign({}, extra), { transferAmount: new bignumber_js_1.BigNumber(transaction.amount) });
|
|
101
|
+
case "BOND":
|
|
102
|
+
return __assign(__assign({}, extra), { bondedAmount: new bignumber_js_1.BigNumber(transaction.amount) });
|
|
103
|
+
case "UNBOND":
|
|
104
|
+
return __assign(__assign({}, extra), { unbondedAmount: new bignumber_js_1.BigNumber(transaction.amount) });
|
|
105
|
+
case "WITHDRAW_UNBONDED":
|
|
106
|
+
return __assign(__assign({}, extra), { withdrawUnbondedAmount: new bignumber_js_1.BigNumber(((_a = account.polkadotResources) === null || _a === void 0 ? void 0 : _a.unlockedBalance) || 0) });
|
|
107
|
+
case "NOMINATE":
|
|
108
|
+
return __assign(__assign({}, extra), { validators: transaction.validators });
|
|
109
|
+
}
|
|
110
|
+
return extra;
|
|
111
|
+
};
|
|
112
|
+
var buildOptimisticOperation = function (account, transaction, fee) {
|
|
113
|
+
var _a;
|
|
114
|
+
var type = ((_a = MODE_TO_TYPE[transaction.mode]) !== null && _a !== void 0 ? _a : MODE_TO_TYPE["default"]);
|
|
115
|
+
var value = type === "OUT"
|
|
116
|
+
? new bignumber_js_1.BigNumber(transaction.amount).plus(fee)
|
|
117
|
+
: new bignumber_js_1.BigNumber(fee);
|
|
118
|
+
var extra = getExtra(type, account, transaction);
|
|
119
|
+
var operation = {
|
|
120
|
+
id: (0, operation_1.encodeOperationId)(account.id, "", type),
|
|
121
|
+
hash: "",
|
|
122
|
+
type: type,
|
|
123
|
+
value: value,
|
|
124
|
+
fee: fee,
|
|
125
|
+
blockHash: null,
|
|
126
|
+
blockHeight: null,
|
|
127
|
+
senders: [account.freshAddress],
|
|
128
|
+
recipients: [transaction.recipient].filter(Boolean),
|
|
129
|
+
accountId: account.id,
|
|
130
|
+
transactionSequenceNumber: (0, logic_1.getNonce)(account),
|
|
131
|
+
date: new Date(),
|
|
132
|
+
extra: extra
|
|
133
|
+
};
|
|
134
|
+
return operation;
|
|
135
|
+
};
|
|
136
|
+
/**
|
|
137
|
+
* Serialize a signed transaction in a format that can be submitted over the
|
|
138
|
+
* Node RPC Interface from the signing payload and signature produced by the
|
|
139
|
+
* remote signer.
|
|
140
|
+
*
|
|
141
|
+
* @param unsigned - The JSON representing the unsigned transaction.
|
|
142
|
+
* @param signature - Signature of the signing payload produced by the remote signer.
|
|
143
|
+
* @param registry - Registry used for constructing the payload.
|
|
144
|
+
*/
|
|
145
|
+
var signExtrinsic = function (unsigned, signature, registry) { return __awaiter(void 0, void 0, void 0, function () {
|
|
146
|
+
var extrinsic;
|
|
147
|
+
return __generator(this, function (_a) {
|
|
148
|
+
extrinsic = registry.createType("Extrinsic", unsigned, {
|
|
149
|
+
version: unsigned.version
|
|
150
|
+
});
|
|
151
|
+
extrinsic.addSignature(unsigned.address, signature, unsigned);
|
|
152
|
+
return [2 /*return*/, extrinsic.toHex()];
|
|
153
|
+
});
|
|
154
|
+
}); };
|
|
155
|
+
exports.signExtrinsic = signExtrinsic;
|
|
156
|
+
/**
|
|
157
|
+
* Sign Extrinsic with a fake signature (for fees estimation).
|
|
158
|
+
*
|
|
159
|
+
* @param unsigned - The JSON representing the unsigned transaction.
|
|
160
|
+
* @param registry - Registry used for constructing the payload.
|
|
161
|
+
*/
|
|
162
|
+
var fakeSignExtrinsic = function (unsigned, registry) { return __awaiter(void 0, void 0, void 0, function () {
|
|
163
|
+
var fakeSignature;
|
|
164
|
+
return __generator(this, function (_a) {
|
|
165
|
+
fakeSignature = (0, util_1.u8aConcat)(new Uint8Array([1]), new Uint8Array(64).fill(0x42));
|
|
166
|
+
return [2 /*return*/, (0, exports.signExtrinsic)(unsigned, fakeSignature, registry)];
|
|
167
|
+
});
|
|
168
|
+
}); };
|
|
169
|
+
exports.fakeSignExtrinsic = fakeSignExtrinsic;
|
|
170
|
+
/**
|
|
171
|
+
* Sign Transaction with Ledger hardware
|
|
172
|
+
*/
|
|
173
|
+
var buildSignOperation = function (withDevice) {
|
|
174
|
+
return function (_a) {
|
|
175
|
+
var account = _a.account, deviceId = _a.deviceId, transaction = _a.transaction;
|
|
176
|
+
return withDevice(deviceId)(function (transport) {
|
|
177
|
+
return new rxjs_1.Observable(function (o) {
|
|
178
|
+
function main() {
|
|
179
|
+
var _a;
|
|
180
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
181
|
+
var transactionToSign, _b, unsigned, registry, payload, polkadot, r, signed, operation;
|
|
182
|
+
return __generator(this, function (_c) {
|
|
183
|
+
switch (_c.label) {
|
|
184
|
+
case 0:
|
|
185
|
+
o.next({
|
|
186
|
+
type: "device-signature-requested"
|
|
187
|
+
});
|
|
188
|
+
if (!transaction.fees) {
|
|
189
|
+
throw new errors_1.FeeNotLoaded();
|
|
190
|
+
}
|
|
191
|
+
transactionToSign = __assign(__assign({}, transaction), { amount: (0, logic_1.calculateAmount)({
|
|
192
|
+
a: account,
|
|
193
|
+
t: transaction
|
|
194
|
+
}) });
|
|
195
|
+
return [4 /*yield*/, (0, js_buildTransaction_1.buildTransaction)(account, transactionToSign, true)];
|
|
196
|
+
case 1:
|
|
197
|
+
_b = _c.sent(), unsigned = _b.unsigned, registry = _b.registry;
|
|
198
|
+
payload = registry
|
|
199
|
+
.createType("ExtrinsicPayload", unsigned, {
|
|
200
|
+
version: unsigned.version
|
|
201
|
+
})
|
|
202
|
+
.toU8a({
|
|
203
|
+
method: true
|
|
204
|
+
});
|
|
205
|
+
polkadot = new hw_app_polkadot_1["default"](transport);
|
|
206
|
+
return [4 /*yield*/, polkadot.sign(account.freshAddressPath, payload)];
|
|
207
|
+
case 2:
|
|
208
|
+
r = _c.sent();
|
|
209
|
+
return [4 /*yield*/, (0, exports.signExtrinsic)(unsigned, r.signature, registry)];
|
|
210
|
+
case 3:
|
|
211
|
+
signed = _c.sent();
|
|
212
|
+
o.next({
|
|
213
|
+
type: "device-signature-granted"
|
|
214
|
+
});
|
|
215
|
+
operation = buildOptimisticOperation(account, transactionToSign, (_a = transactionToSign.fees) !== null && _a !== void 0 ? _a : new bignumber_js_1.BigNumber(0));
|
|
216
|
+
o.next({
|
|
217
|
+
type: "signed",
|
|
218
|
+
signedOperation: {
|
|
219
|
+
operation: operation,
|
|
220
|
+
signature: signed,
|
|
221
|
+
expirationDate: null
|
|
222
|
+
}
|
|
223
|
+
});
|
|
224
|
+
return [2 /*return*/];
|
|
225
|
+
}
|
|
226
|
+
});
|
|
227
|
+
});
|
|
228
|
+
}
|
|
229
|
+
main().then(function () { return o.complete(); }, function (e) { return o.error(e); });
|
|
230
|
+
});
|
|
231
|
+
});
|
|
232
|
+
};
|
|
233
|
+
};
|
|
234
|
+
exports["default"] = buildSignOperation;
|
|
235
|
+
//# sourceMappingURL=js-signOperation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"js-signOperation.js","sourceRoot":"","sources":["../src/js-signOperation.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,6CAAyC;AACzC,6BAAkC;AAElC,uCAA2C;AAC3C,2CAAgD;AAChD,8EAAiD;AAUjD,gEAAuE;AACvE,6DAAyD;AACzD,iCAAiE;AACjE,IAAM,YAAY,GAAG;IACnB,IAAI,EAAE,KAAK;IACX,IAAI,EAAE,MAAM;IACZ,MAAM,EAA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IAAI,EAAE,CAAC,IAAI,CACT,cAAM,OAAA,CAAC,CAAC,QAAQ,EAAE,EAAZ,CAAY,EAClB,UAAC,CAAC,IAAK,OAAA,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,EAAV,CAAU,CAClB,CAAC;YACJ,CAAC,CAAC;QA5DF,CA4DE,CACL;IA/DD,CA+DC;AAxEH,CAwEG,CAAC;AAEN,qBAAe,kBAAkB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"js-synchronisation.d.ts","sourceRoot":"","sources":["../src/js-synchronisation.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,2CAA2C,CAAC;AAKjF,eAAO,MAAM,eAAe,EAAE,eAiD7B,CAAC"}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __assign = (this && this.__assign) || function () {
|
|
3
|
+
__assign = Object.assign || function(t) {
|
|
4
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
+
s = arguments[i];
|
|
6
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
+
t[p] = s[p];
|
|
8
|
+
}
|
|
9
|
+
return t;
|
|
10
|
+
};
|
|
11
|
+
return __assign.apply(this, arguments);
|
|
12
|
+
};
|
|
13
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
14
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
15
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
16
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
17
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
18
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
19
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
20
|
+
});
|
|
21
|
+
};
|
|
22
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
23
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
24
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
25
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
26
|
+
function step(op) {
|
|
27
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
28
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
29
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
30
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
31
|
+
switch (op[0]) {
|
|
32
|
+
case 0: case 1: t = op; break;
|
|
33
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
34
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
35
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
36
|
+
default:
|
|
37
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
38
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
39
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
40
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
41
|
+
if (t[2]) _.ops.pop();
|
|
42
|
+
_.trys.pop(); continue;
|
|
43
|
+
}
|
|
44
|
+
op = body.call(thisArg, _);
|
|
45
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
46
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
exports.__esModule = true;
|
|
50
|
+
exports.getAccountShape = void 0;
|
|
51
|
+
var index_1 = require("@ledgerhq/coin-framework/account/index");
|
|
52
|
+
var jsHelpers_1 = require("@ledgerhq/coin-framework/bridge/jsHelpers");
|
|
53
|
+
var api_1 = require("./api");
|
|
54
|
+
var polkadot_crypto_1 = require("./polkadot-crypto");
|
|
55
|
+
var getAccountShape = function (info) { return __awaiter(void 0, void 0, void 0, function () {
|
|
56
|
+
var address, initialAccount, currency, derivationMode, oldOperations, startAt, _a, blockHeight, balance, spendableBalance, nonce, lockedBalance, controller, stash, unlockedBalance, unlockingBalance, unlockings, nominations, numSlashingSpans, accountId, newOperations, operations, shape;
|
|
57
|
+
return __generator(this, function (_b) {
|
|
58
|
+
switch (_b.label) {
|
|
59
|
+
case 0: return [4 /*yield*/, (0, polkadot_crypto_1.loadPolkadotCrypto)()];
|
|
60
|
+
case 1:
|
|
61
|
+
_b.sent();
|
|
62
|
+
address = info.address, initialAccount = info.initialAccount, currency = info.currency, derivationMode = info.derivationMode;
|
|
63
|
+
oldOperations = (initialAccount === null || initialAccount === void 0 ? void 0 : initialAccount.operations) || [];
|
|
64
|
+
startAt = oldOperations.length
|
|
65
|
+
? (oldOperations[0].blockHeight || 0) + 1
|
|
66
|
+
: 0;
|
|
67
|
+
return [4 /*yield*/, (0, api_1.getAccount)(address)];
|
|
68
|
+
case 2:
|
|
69
|
+
_a = _b.sent(), blockHeight = _a.blockHeight, balance = _a.balance, spendableBalance = _a.spendableBalance, nonce = _a.nonce, lockedBalance = _a.lockedBalance, controller = _a.controller, stash = _a.stash, unlockedBalance = _a.unlockedBalance, unlockingBalance = _a.unlockingBalance, unlockings = _a.unlockings, nominations = _a.nominations, numSlashingSpans = _a.numSlashingSpans;
|
|
70
|
+
accountId = (0, index_1.encodeAccountId)({
|
|
71
|
+
type: "js",
|
|
72
|
+
version: "2",
|
|
73
|
+
currencyId: currency.id,
|
|
74
|
+
xpubOrAddress: address,
|
|
75
|
+
derivationMode: derivationMode
|
|
76
|
+
});
|
|
77
|
+
return [4 /*yield*/, (0, api_1.getOperations)(accountId, address, startAt)];
|
|
78
|
+
case 3:
|
|
79
|
+
newOperations = _b.sent();
|
|
80
|
+
operations = (0, jsHelpers_1.mergeOps)(oldOperations, newOperations);
|
|
81
|
+
shape = {
|
|
82
|
+
id: accountId,
|
|
83
|
+
balance: balance,
|
|
84
|
+
spendableBalance: spendableBalance,
|
|
85
|
+
operationsCount: operations.length,
|
|
86
|
+
blockHeight: blockHeight,
|
|
87
|
+
polkadotResources: {
|
|
88
|
+
nonce: nonce,
|
|
89
|
+
controller: controller,
|
|
90
|
+
stash: stash,
|
|
91
|
+
lockedBalance: lockedBalance,
|
|
92
|
+
unlockedBalance: unlockedBalance,
|
|
93
|
+
unlockingBalance: unlockingBalance,
|
|
94
|
+
unlockings: unlockings,
|
|
95
|
+
nominations: nominations,
|
|
96
|
+
numSlashingSpans: numSlashingSpans
|
|
97
|
+
}
|
|
98
|
+
};
|
|
99
|
+
return [2 /*return*/, __assign(__assign({}, shape), { operations: operations })];
|
|
100
|
+
}
|
|
101
|
+
});
|
|
102
|
+
}); };
|
|
103
|
+
exports.getAccountShape = getAccountShape;
|
|
104
|
+
//# sourceMappingURL=js-synchronisation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"js-synchronisation.js","sourceRoot":"","sources":["../src/js-synchronisation.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,gEAAyE;AAEzE,uEAAqE;AACrE,6BAAkD;AAClD,qDAAuD;AAEhD,IAAM,eAAe,GAAoB,UAAO,IAAI;;;;oBACzD,qBAAM,IAAA,oCAAkB,GAAE,EAAA;;gBAA1B,SAA0B,CAAC;gBACnB,OAAO,GAA+C,IAAI,QAAnD,EAAE,cAAc,GAA+B,IAAI,eAAnC,EAAE,QAAQ,GAAqB,IAAI,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;wBAChB,UAAU,YAAA;wBACV,WAAW,aAAA;wBACX,gBAAgB,kBAAA;qBACjB;iBACF,CAAC;gBACF,sBAAO,sBAAK,KAAK,KAAE,UAAU,YAAA,GAAsB,EAAC;;;KACrD,CAAC;AAjDW,QAAA,eAAe,mBAiD1B"}
|
package/lib/logic.d.ts
ADDED
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import { BigNumber } from "bignumber.js";
|
|
2
|
+
import type { Account, OperationType } from "@ledgerhq/types-live";
|
|
3
|
+
import type { PolkadotAccount, Transaction } from "./types";
|
|
4
|
+
export declare const EXISTENTIAL_DEPOSIT: BigNumber;
|
|
5
|
+
export declare const EXISTENTIAL_DEPOSIT_RECOMMENDED_MARGIN: BigNumber;
|
|
6
|
+
export declare const MAX_NOMINATIONS = 16;
|
|
7
|
+
export declare const MAX_UNLOCKINGS = 32;
|
|
8
|
+
export declare const PRELOAD_MAX_AGE: number;
|
|
9
|
+
export declare const MAX_AMOUNT_INPUT = 18446744073709552000;
|
|
10
|
+
export declare const FEES_SAFETY_BUFFER: BigNumber;
|
|
11
|
+
/**
|
|
12
|
+
* Returns true if account is a stash.
|
|
13
|
+
* When the account is a stash, we have the information of which account is the controller
|
|
14
|
+
*
|
|
15
|
+
* @param {PolkadotAccount} a
|
|
16
|
+
*/
|
|
17
|
+
export declare const isStash: (a: PolkadotAccount) => boolean;
|
|
18
|
+
/**
|
|
19
|
+
* Returns true if account is a controller.
|
|
20
|
+
* when account is a controller, we have the information of which stash it controls
|
|
21
|
+
*
|
|
22
|
+
* @param {PolkadotAccount} a
|
|
23
|
+
*/
|
|
24
|
+
export declare const isController: (a: PolkadotAccount) => boolean;
|
|
25
|
+
/**
|
|
26
|
+
* Returns true if account is controlled by an external account (not self)
|
|
27
|
+
*
|
|
28
|
+
* @param {PolkadotAccount} a
|
|
29
|
+
*/
|
|
30
|
+
export declare const hasExternalController: (a: PolkadotAccount) => boolean;
|
|
31
|
+
/**
|
|
32
|
+
* Returns true if account controls an external stash (not self)
|
|
33
|
+
*
|
|
34
|
+
* @param {PolkadotAccount} a
|
|
35
|
+
*/
|
|
36
|
+
export declare const hasExternalStash: (a: PolkadotAccount) => boolean;
|
|
37
|
+
/**
|
|
38
|
+
* Must have the minimum balance to bond
|
|
39
|
+
*
|
|
40
|
+
* @param {PolkadotAccount} a
|
|
41
|
+
*/
|
|
42
|
+
export declare const canBond: (a: Account) => boolean;
|
|
43
|
+
/**
|
|
44
|
+
* Get the minimum bond amount required to bond/rebond
|
|
45
|
+
*
|
|
46
|
+
* @param {PolkadotAccount} a
|
|
47
|
+
*/
|
|
48
|
+
export declare const getMinimumAmountToBond: (a: PolkadotAccount, minimumBondBalance: BigNumber | undefined) => BigNumber;
|
|
49
|
+
/**
|
|
50
|
+
* Return true if the account has at least the current minimum bonded balance required by the network
|
|
51
|
+
*
|
|
52
|
+
* @param {PolkadotAccount} a
|
|
53
|
+
*/
|
|
54
|
+
export declare const hasMinimumBondBalance: (a: PolkadotAccount) => boolean;
|
|
55
|
+
/**
|
|
56
|
+
* Return true if some operation with type is pending and not yet synchronized
|
|
57
|
+
*
|
|
58
|
+
* @param {PolkadotAccount} a
|
|
59
|
+
*/
|
|
60
|
+
export declare const hasPendingOperationType: (a: Account, type: OperationType) => boolean;
|
|
61
|
+
/**
|
|
62
|
+
* Retyrns true if has reached the maximum of unlocking slots
|
|
63
|
+
*
|
|
64
|
+
* @param {PolkadotAccount} a
|
|
65
|
+
*/
|
|
66
|
+
export declare const hasMaxUnlockings: (a: PolkadotAccount) => boolean;
|
|
67
|
+
/**
|
|
68
|
+
* Return true if account has enough Locked Balance to rebond
|
|
69
|
+
*
|
|
70
|
+
* @param {PolkadotAccount} a
|
|
71
|
+
*/
|
|
72
|
+
export declare const hasLockedBalance: (a: PolkadotAccount) => boolean;
|
|
73
|
+
/**
|
|
74
|
+
* Must have locked Balance
|
|
75
|
+
*
|
|
76
|
+
* @param {PolkadotAccount} a
|
|
77
|
+
*/
|
|
78
|
+
export declare const canUnbond: (a: PolkadotAccount) => boolean;
|
|
79
|
+
/**
|
|
80
|
+
* Returns true if an account can nominate
|
|
81
|
+
*
|
|
82
|
+
* @param {PolkadotAccount} a
|
|
83
|
+
*/
|
|
84
|
+
export declare const canNominate: (a: PolkadotAccount) => boolean;
|
|
85
|
+
/**
|
|
86
|
+
* Returns true if account must do a first bond - false for a bond extra
|
|
87
|
+
*
|
|
88
|
+
* @param {Account} a
|
|
89
|
+
*/
|
|
90
|
+
export declare const isFirstBond: (a: PolkadotAccount) => boolean;
|
|
91
|
+
/**
|
|
92
|
+
* Returns nonce for an account
|
|
93
|
+
*
|
|
94
|
+
* @param {Account} a
|
|
95
|
+
*/
|
|
96
|
+
export declare const getNonce: (a: PolkadotAccount) => number;
|
|
97
|
+
/**
|
|
98
|
+
* Calculates correct amount if useAllAmount
|
|
99
|
+
*
|
|
100
|
+
* @param {*} param
|
|
101
|
+
*/
|
|
102
|
+
export declare const calculateAmount: ({ a, t, }: {
|
|
103
|
+
a: PolkadotAccount;
|
|
104
|
+
t: Transaction;
|
|
105
|
+
}) => BigNumber;
|
|
106
|
+
export declare const getMinimumBalance: (a: Account) => BigNumber;
|
|
107
|
+
//# sourceMappingURL=logic.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logic.d.ts","sourceRoot":"","sources":["../src/logic.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,KAAK,EAAE,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AACnE,OAAO,KAAK,EAAE,eAAe,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAG5D,eAAO,MAAM,mBAAmB,WAA6B,CAAC;AAC9D,eAAO,MAAM,sCAAsC,WAA4B,CAAC;AAChF,eAAO,MAAM,eAAe,KAAK,CAAC;AAClC,eAAO,MAAM,cAAc,KAAK,CAAC;AACjC,eAAO,MAAM,eAAe,QAAY,CAAC;AAE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