@initia/initia.js 0.0.30 → 0.0.32
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/bundle.js +1 -1
- package/dist/bundle.js.map +1 -1
- package/dist/bundle.node.js +1 -1
- package/dist/bundle.node.js.LICENSE.txt +2 -0
- package/dist/bundle.node.js.map +1 -1
- package/dist/client/lcd/LCDClient.d.ts +2 -2
- package/dist/client/lcd/LCDClient.js +1 -1
- package/dist/client/lcd/LCDClient.js.map +1 -1
- package/dist/client/lcd/LCDUtils.d.ts +1 -1
- package/dist/client/lcd/LCDUtils.js +1 -1
- package/dist/client/lcd/LCDUtils.js.map +1 -1
- package/dist/client/lcd/api/MoveAPI.d.ts +2 -0
- package/dist/client/lcd/api/MoveAPI.js +2 -0
- package/dist/client/lcd/api/MoveAPI.js.map +1 -1
- package/dist/client/lcd/api/MstakingAPI.d.ts +97 -0
- package/dist/client/lcd/api/MstakingAPI.js +294 -0
- package/dist/client/lcd/api/MstakingAPI.js.map +1 -0
- package/dist/client/lcd/api/index.d.ts +1 -1
- package/dist/client/lcd/api/index.js +1 -1
- package/dist/client/lcd/api/index.js.map +1 -1
- package/dist/core/Msg.d.ts +5 -5
- package/dist/core/Msg.js +9 -9
- package/dist/core/Msg.js.map +1 -1
- package/dist/core/Tx.d.ts +1 -1
- package/dist/core/gov/Proposal.d.ts +5 -5
- package/dist/core/gov/Proposal.js +6 -12
- package/dist/core/gov/Proposal.js.map +1 -1
- package/dist/core/index.d.ts +5 -5
- package/dist/core/index.js +6 -6
- package/dist/core/index.js.map +1 -1
- package/dist/core/move/msgs/MsgExecute.d.ts +1 -1
- package/dist/core/move/msgs/MsgExecute.js +1 -1
- package/dist/core/move/msgs/MsgPublish.d.ts +8 -3
- package/dist/core/move/msgs/MsgPublish.js +16 -11
- package/dist/core/move/msgs/MsgPublish.js.map +1 -1
- package/dist/core/move/msgs/MsgScript.d.ts +2 -2
- package/dist/core/move/msgs/MsgScript.js +2 -2
- package/dist/core/move/proposals/ExecuteOperation.d.ts +51 -0
- package/dist/core/move/proposals/ExecuteOperation.js +100 -0
- package/dist/core/move/proposals/ExecuteOperation.js.map +1 -0
- package/dist/core/move/proposals/OperationsProposal.d.ts +57 -0
- package/dist/core/move/proposals/OperationsProposal.js +127 -0
- package/dist/core/move/proposals/OperationsProposal.js.map +1 -0
- package/dist/core/move/proposals/PublishOperation.d.ts +34 -0
- package/dist/core/move/proposals/PublishOperation.js +76 -0
- package/dist/core/move/proposals/PublishOperation.js.map +1 -0
- package/dist/core/move/proposals/index.d.ts +3 -2
- package/dist/core/move/proposals/index.js +3 -2
- package/dist/core/move/proposals/index.js.map +1 -1
- package/dist/core/mstaking/Delegation.d.ts +45 -0
- package/dist/core/mstaking/Delegation.js +89 -0
- package/dist/core/mstaking/Delegation.js.map +1 -0
- package/dist/core/mstaking/Redelegation.d.ts +97 -0
- package/dist/core/mstaking/Redelegation.js +174 -0
- package/dist/core/mstaking/Redelegation.js.map +1 -0
- package/dist/core/mstaking/UnbondingDelegation.d.ts +75 -0
- package/dist/core/mstaking/UnbondingDelegation.js +143 -0
- package/dist/core/mstaking/UnbondingDelegation.js.map +1 -0
- package/dist/core/mstaking/Validator.d.ts +173 -0
- package/dist/core/mstaking/Validator.js +287 -0
- package/dist/core/mstaking/Validator.js.map +1 -0
- package/dist/core/mstaking/msgs/MsgBeginRedelegate.d.ts +51 -0
- package/dist/core/mstaking/msgs/MsgBeginRedelegate.js +99 -0
- package/dist/core/mstaking/msgs/MsgBeginRedelegate.js.map +1 -0
- package/dist/core/mstaking/msgs/MsgCreateValidator.d.ts +60 -0
- package/dist/core/mstaking/msgs/MsgCreateValidator.js +110 -0
- package/dist/core/mstaking/msgs/MsgCreateValidator.js.map +1 -0
- package/dist/core/mstaking/msgs/MsgDelegate.d.ts +46 -0
- package/dist/core/mstaking/msgs/MsgDelegate.js +93 -0
- package/dist/core/mstaking/msgs/MsgDelegate.js.map +1 -0
- package/dist/core/mstaking/msgs/MsgEditValidator.d.ts +50 -0
- package/dist/core/mstaking/msgs/MsgEditValidator.js +111 -0
- package/dist/core/mstaking/msgs/MsgEditValidator.js.map +1 -0
- package/dist/core/mstaking/msgs/MsgUndelegate.d.ts +46 -0
- package/dist/core/mstaking/msgs/MsgUndelegate.js +93 -0
- package/dist/core/mstaking/msgs/MsgUndelegate.js.map +1 -0
- package/dist/core/mstaking/msgs/index.d.ts +16 -0
- package/dist/core/mstaking/msgs/index.js +22 -0
- package/dist/core/mstaking/msgs/index.js.map +1 -0
- package/dist/core/params/proposals/ParameterChangeProposal.d.ts +1 -5
- package/dist/core/params/proposals/ParameterChangeProposal.js +1 -5
- package/dist/core/params/proposals/ParameterChangeProposal.js.map +1 -1
- package/dist/key/index.d.ts +1 -0
- package/dist/key/index.js +1 -0
- package/dist/key/index.js.map +1 -1
- package/dist/key/ledger/LedgerKey.d.ts +55 -0
- package/dist/key/ledger/LedgerKey.js +377 -0
- package/dist/key/ledger/LedgerKey.js.map +1 -0
- package/dist/key/ledger/app.d.ts +39 -0
- package/dist/key/ledger/app.js +178 -0
- package/dist/key/ledger/app.js.map +1 -0
- package/dist/key/ledger/constants.d.ts +24 -0
- package/dist/key/ledger/constants.js +50 -0
- package/dist/key/ledger/constants.js.map +1 -0
- package/dist/key/ledger/device.d.ts +11 -0
- package/dist/key/ledger/device.js +379 -0
- package/dist/key/ledger/device.js.map +1 -0
- package/dist/key/ledger/index.d.ts +5 -0
- package/dist/key/ledger/index.js +25 -0
- package/dist/key/ledger/index.js.map +1 -0
- package/dist/key/ledger/types.d.ts +44 -0
- package/dist/key/ledger/types.js +3 -0
- package/dist/key/ledger/types.js.map +1 -0
- package/dist/util/bcs.d.ts +1 -1
- package/package.json +9 -2
|
@@ -0,0 +1,377 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __extends = (this && this.__extends) || (function () {
|
|
3
|
+
var extendStatics = function (d, b) {
|
|
4
|
+
extendStatics = Object.setPrototypeOf ||
|
|
5
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
+
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
7
|
+
return extendStatics(d, b);
|
|
8
|
+
};
|
|
9
|
+
return function (d, b) {
|
|
10
|
+
if (typeof b !== "function" && b !== null)
|
|
11
|
+
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
12
|
+
extendStatics(d, b);
|
|
13
|
+
function __() { this.constructor = d; }
|
|
14
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
|
+
};
|
|
16
|
+
})();
|
|
17
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
18
|
+
if (k2 === undefined) k2 = k;
|
|
19
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
20
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
21
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
22
|
+
}
|
|
23
|
+
Object.defineProperty(o, k2, desc);
|
|
24
|
+
}) : (function(o, m, k, k2) {
|
|
25
|
+
if (k2 === undefined) k2 = k;
|
|
26
|
+
o[k2] = m[k];
|
|
27
|
+
}));
|
|
28
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
29
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
30
|
+
}) : function(o, v) {
|
|
31
|
+
o["default"] = v;
|
|
32
|
+
});
|
|
33
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
34
|
+
if (mod && mod.__esModule) return mod;
|
|
35
|
+
var result = {};
|
|
36
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
37
|
+
__setModuleDefault(result, mod);
|
|
38
|
+
return result;
|
|
39
|
+
};
|
|
40
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
41
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
42
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
43
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
44
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
45
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
46
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
47
|
+
});
|
|
48
|
+
};
|
|
49
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
50
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
51
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
52
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
53
|
+
function step(op) {
|
|
54
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
55
|
+
while (_) try {
|
|
56
|
+
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;
|
|
57
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
58
|
+
switch (op[0]) {
|
|
59
|
+
case 0: case 1: t = op; break;
|
|
60
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
61
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
62
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
63
|
+
default:
|
|
64
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
65
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
66
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
67
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
68
|
+
if (t[2]) _.ops.pop();
|
|
69
|
+
_.trys.pop(); continue;
|
|
70
|
+
}
|
|
71
|
+
op = body.call(thisArg, _);
|
|
72
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
73
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
77
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
78
|
+
};
|
|
79
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
80
|
+
exports.LedgerKey = exports.LedgerError = void 0;
|
|
81
|
+
var semver = __importStar(require("semver"));
|
|
82
|
+
var app_1 = __importDefault(require("./app"));
|
|
83
|
+
var __1 = require("../..");
|
|
84
|
+
var Key_1 = require("../Key");
|
|
85
|
+
var MnemonicKey_1 = require("../MnemonicKey");
|
|
86
|
+
var secp256k1_1 = require("secp256k1");
|
|
87
|
+
var INTERACTION_TIMEOUT = 120;
|
|
88
|
+
var REQUIRED_APP_VERSION = '1.0.0';
|
|
89
|
+
var LedgerError = /** @class */ (function (_super) {
|
|
90
|
+
__extends(LedgerError, _super);
|
|
91
|
+
function LedgerError(message) {
|
|
92
|
+
var _this = _super.call(this, message) || this;
|
|
93
|
+
_this.name = 'LedgerError';
|
|
94
|
+
return _this;
|
|
95
|
+
}
|
|
96
|
+
return LedgerError;
|
|
97
|
+
}(Error));
|
|
98
|
+
exports.LedgerError = LedgerError;
|
|
99
|
+
/**
|
|
100
|
+
* Key implementation that uses Ledger to sign transactions. Keys should be registered
|
|
101
|
+
* in Ledger device
|
|
102
|
+
*/
|
|
103
|
+
var LedgerKey = /** @class */ (function (_super) {
|
|
104
|
+
__extends(LedgerKey, _super);
|
|
105
|
+
/**
|
|
106
|
+
*
|
|
107
|
+
* @param transport transporter for LedgerKey
|
|
108
|
+
*/
|
|
109
|
+
function LedgerKey(transport) {
|
|
110
|
+
var _this = _super.call(this) || this;
|
|
111
|
+
_this.transport = transport;
|
|
112
|
+
_this.path = [44, MnemonicKey_1.INIT_COIN_TYPE, 0, 0, 0];
|
|
113
|
+
_this.app = new app_1.default(_this.transport);
|
|
114
|
+
return _this;
|
|
115
|
+
}
|
|
116
|
+
Object.defineProperty(LedgerKey.prototype, "accAddress", {
|
|
117
|
+
/**
|
|
118
|
+
* Initia account address. `init-` prefixed.
|
|
119
|
+
*/
|
|
120
|
+
get: function () {
|
|
121
|
+
if (!this.publicKey) {
|
|
122
|
+
throw new Error('Ledger is unintialized. Initialize it first.');
|
|
123
|
+
}
|
|
124
|
+
return this.publicKey.address();
|
|
125
|
+
},
|
|
126
|
+
enumerable: false,
|
|
127
|
+
configurable: true
|
|
128
|
+
});
|
|
129
|
+
/**
|
|
130
|
+
* create and return initialized ledger key
|
|
131
|
+
*/
|
|
132
|
+
LedgerKey.create = function (transport, index) {
|
|
133
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
134
|
+
var key;
|
|
135
|
+
return __generator(this, function (_a) {
|
|
136
|
+
switch (_a.label) {
|
|
137
|
+
case 0:
|
|
138
|
+
if (!!transport) return [3 /*break*/, 2];
|
|
139
|
+
return [4 /*yield*/, createTransport()];
|
|
140
|
+
case 1:
|
|
141
|
+
transport = _a.sent();
|
|
142
|
+
_a.label = 2;
|
|
143
|
+
case 2:
|
|
144
|
+
key = new LedgerKey(transport);
|
|
145
|
+
if (index != undefined) {
|
|
146
|
+
key.path[4] = index;
|
|
147
|
+
}
|
|
148
|
+
if (transport && typeof transport.on === 'function') {
|
|
149
|
+
transport.on('disconnect', function () {
|
|
150
|
+
key.transport = null;
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
return [4 /*yield*/, key.initialize().catch(handleConnectError)];
|
|
154
|
+
case 3:
|
|
155
|
+
_a.sent();
|
|
156
|
+
return [2 /*return*/, key];
|
|
157
|
+
}
|
|
158
|
+
});
|
|
159
|
+
});
|
|
160
|
+
};
|
|
161
|
+
/**
|
|
162
|
+
* initialize LedgerKey.
|
|
163
|
+
* it loads accAddress and publicKey from connected Ledger
|
|
164
|
+
*/
|
|
165
|
+
LedgerKey.prototype.initialize = function () {
|
|
166
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
167
|
+
var res, appName, _a, major, minor, patch, version;
|
|
168
|
+
return __generator(this, function (_b) {
|
|
169
|
+
switch (_b.label) {
|
|
170
|
+
case 0: return [4 /*yield*/, this.app.initialize()];
|
|
171
|
+
case 1:
|
|
172
|
+
res = _b.sent();
|
|
173
|
+
appName = this.app.getInfo().app_name;
|
|
174
|
+
if (appName !== 'Initia') {
|
|
175
|
+
throw new LedgerError('Open the Initia app in the Ledger');
|
|
176
|
+
}
|
|
177
|
+
_a = this.app.getVersion(), major = _a.major, minor = _a.minor, patch = _a.patch;
|
|
178
|
+
version = "".concat(major, ".").concat(minor, ".").concat(patch);
|
|
179
|
+
if (appName === 'Initia' && semver.lt(version, REQUIRED_APP_VERSION)) {
|
|
180
|
+
throw new LedgerError('Outdated version: Update Ledger Initia App to the latest version');
|
|
181
|
+
}
|
|
182
|
+
checkLedgerErrors(res);
|
|
183
|
+
return [4 /*yield*/, this.loadAccountDetails()];
|
|
184
|
+
case 2:
|
|
185
|
+
_b.sent();
|
|
186
|
+
return [2 /*return*/];
|
|
187
|
+
}
|
|
188
|
+
});
|
|
189
|
+
});
|
|
190
|
+
};
|
|
191
|
+
/**
|
|
192
|
+
* get Address and Pubkey from Ledger
|
|
193
|
+
*/
|
|
194
|
+
LedgerKey.prototype.loadAccountDetails = function () {
|
|
195
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
196
|
+
var res;
|
|
197
|
+
return __generator(this, function (_a) {
|
|
198
|
+
switch (_a.label) {
|
|
199
|
+
case 0: return [4 /*yield*/, this.app.getAddressAndPubKey(this.path, 'init')];
|
|
200
|
+
case 1:
|
|
201
|
+
res = _a.sent();
|
|
202
|
+
checkLedgerErrors(res);
|
|
203
|
+
this.publicKey = new __1.SimplePublicKey(Buffer.from(res.compressed_pk.data).toString('base64'));
|
|
204
|
+
return [2 /*return*/, this];
|
|
205
|
+
}
|
|
206
|
+
});
|
|
207
|
+
});
|
|
208
|
+
};
|
|
209
|
+
LedgerKey.prototype.sign = function (message) {
|
|
210
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
211
|
+
var res;
|
|
212
|
+
return __generator(this, function (_a) {
|
|
213
|
+
switch (_a.label) {
|
|
214
|
+
case 0:
|
|
215
|
+
if (!this.publicKey) {
|
|
216
|
+
this.loadAccountDetails();
|
|
217
|
+
}
|
|
218
|
+
return [4 /*yield*/, this.app.sign(this.path, message)];
|
|
219
|
+
case 1:
|
|
220
|
+
res = _a.sent();
|
|
221
|
+
checkLedgerErrors(res);
|
|
222
|
+
return [2 /*return*/, Buffer.from((0, secp256k1_1.signatureImport)(Buffer.from(res.signature)))];
|
|
223
|
+
}
|
|
224
|
+
});
|
|
225
|
+
});
|
|
226
|
+
};
|
|
227
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
228
|
+
LedgerKey.prototype.createSignature = function (_tx) {
|
|
229
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
230
|
+
return __generator(this, function (_a) {
|
|
231
|
+
throw new Error('direct sign mode is not supported');
|
|
232
|
+
});
|
|
233
|
+
});
|
|
234
|
+
};
|
|
235
|
+
LedgerKey.prototype.getAppAddressAndPubKey = function () {
|
|
236
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
237
|
+
return __generator(this, function (_a) {
|
|
238
|
+
return [2 /*return*/, this.app.getAddressAndPubKey(this.path, 'init')];
|
|
239
|
+
});
|
|
240
|
+
});
|
|
241
|
+
};
|
|
242
|
+
LedgerKey.prototype.getAppInfo = function () {
|
|
243
|
+
return this.app.getInfo();
|
|
244
|
+
};
|
|
245
|
+
LedgerKey.prototype.getAppDeviceInfo = function () {
|
|
246
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
247
|
+
return __generator(this, function (_a) {
|
|
248
|
+
return [2 /*return*/, this.app.getDeviceInfo()];
|
|
249
|
+
});
|
|
250
|
+
});
|
|
251
|
+
};
|
|
252
|
+
LedgerKey.prototype.getAppPublicKey = function () {
|
|
253
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
254
|
+
return __generator(this, function (_a) {
|
|
255
|
+
return [2 /*return*/, this.app.getPublicKey(this.path)];
|
|
256
|
+
});
|
|
257
|
+
});
|
|
258
|
+
};
|
|
259
|
+
LedgerKey.prototype.getAppVersion = function () {
|
|
260
|
+
return this.app.getVersion();
|
|
261
|
+
};
|
|
262
|
+
LedgerKey.prototype.showAddressAndPubKey = function () {
|
|
263
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
264
|
+
return __generator(this, function (_a) {
|
|
265
|
+
return [2 /*return*/, this.app.showAddressAndPubKey(this.path, 'init')];
|
|
266
|
+
});
|
|
267
|
+
});
|
|
268
|
+
};
|
|
269
|
+
return LedgerKey;
|
|
270
|
+
}(Key_1.Key));
|
|
271
|
+
exports.LedgerKey = LedgerKey;
|
|
272
|
+
var handleConnectError = function (err) {
|
|
273
|
+
var message = err.message.trim();
|
|
274
|
+
if (message.startsWith('The device is already open')) {
|
|
275
|
+
// ignore this error
|
|
276
|
+
return; //transport
|
|
277
|
+
}
|
|
278
|
+
if (err.name === 'TransportOpenUserCancelled') {
|
|
279
|
+
throw new LedgerError("Couldn't find the Ledger. Check the Ledger is plugged in and unlocked.");
|
|
280
|
+
}
|
|
281
|
+
/* istanbul ignore next: specific error rewrite */
|
|
282
|
+
if (message.startsWith('No WebUSB interface found for the Ledger device')) {
|
|
283
|
+
throw new LedgerError("Couldn't connect to a Ledger device. Use Ledger Live to upgrade the Ledger firmware to version ".concat(REQUIRED_APP_VERSION, " or later."));
|
|
284
|
+
}
|
|
285
|
+
/* istanbul ignore next: specific error rewrite */
|
|
286
|
+
if (message.startsWith('Unable to claim interface')) {
|
|
287
|
+
// apparently can't use it in several tabs in parallel
|
|
288
|
+
throw new LedgerError("Couldn't access Ledger device. Is it being used in another tab?");
|
|
289
|
+
}
|
|
290
|
+
/* istanbul ignore next: specific error rewrite */
|
|
291
|
+
if (message.startsWith('Transport not defined')) {
|
|
292
|
+
// apparently can't use it in several tabs in parallel
|
|
293
|
+
throw new LedgerError("Couldn't access Ledger device. Is it being used in another tab?");
|
|
294
|
+
}
|
|
295
|
+
/* istanbul ignore next: specific error rewrite */
|
|
296
|
+
if (message.startsWith('Not supported')) {
|
|
297
|
+
throw new LedgerError("This browser doesn't support WebUSB yet. Update it to the latest version.");
|
|
298
|
+
}
|
|
299
|
+
/* istanbul ignore next: specific error rewrite */
|
|
300
|
+
if (message.startsWith('No device selected')) {
|
|
301
|
+
throw new LedgerError("Couldn't find the Ledger. Check the Ledger is plugged in and unlocked.");
|
|
302
|
+
}
|
|
303
|
+
// throw unknown error
|
|
304
|
+
throw err;
|
|
305
|
+
};
|
|
306
|
+
var checkLedgerErrors = function (response) {
|
|
307
|
+
if (!response) {
|
|
308
|
+
return;
|
|
309
|
+
}
|
|
310
|
+
var error_message = response.error_message, device_locked = response.device_locked;
|
|
311
|
+
if (device_locked) {
|
|
312
|
+
throw new LedgerError("Ledger's screensaver mode is on");
|
|
313
|
+
}
|
|
314
|
+
if (error_message.startsWith('TransportRaceCondition')) {
|
|
315
|
+
throw new LedgerError('Finish previous action in Ledger');
|
|
316
|
+
}
|
|
317
|
+
else if (error_message.startsWith('DisconnectedDeviceDuringOperation')) {
|
|
318
|
+
throw new LedgerError('Open the Initia app in the Ledger');
|
|
319
|
+
}
|
|
320
|
+
switch (error_message) {
|
|
321
|
+
case 'U2F: Timeout':
|
|
322
|
+
throw new LedgerError("Couldn't find a connected and unlocked Ledger device");
|
|
323
|
+
case 'App does not seem to be open':
|
|
324
|
+
throw new LedgerError('Open the Initia app in the Ledger');
|
|
325
|
+
case 'Command not allowed':
|
|
326
|
+
throw new LedgerError('Transaction rejected');
|
|
327
|
+
case 'Transaction rejected':
|
|
328
|
+
throw new LedgerError('User rejected the transaction');
|
|
329
|
+
case 'Unknown Status Code: 26628':
|
|
330
|
+
throw new LedgerError("Ledger's screensaver mode is on");
|
|
331
|
+
case 'Instruction not supported':
|
|
332
|
+
throw new LedgerError('Check the Ledger is running latest version of Initia');
|
|
333
|
+
case 'No errors':
|
|
334
|
+
break;
|
|
335
|
+
default:
|
|
336
|
+
throw new LedgerError(error_message);
|
|
337
|
+
}
|
|
338
|
+
};
|
|
339
|
+
var isWindows = function (platform) { return platform.indexOf('Win') > -1; };
|
|
340
|
+
var checkBrowser = function (userAgent) {
|
|
341
|
+
var ua = userAgent.toLowerCase();
|
|
342
|
+
var isChrome = /chrome|crios/.test(ua) && !/edge|opr\//.test(ua);
|
|
343
|
+
var isBrave = isChrome && !window.google;
|
|
344
|
+
if (!isChrome && !isBrave) {
|
|
345
|
+
throw new LedgerError("This browser doesn't support Ledger devices");
|
|
346
|
+
}
|
|
347
|
+
return isChrome ? 'chrome' : 'brave';
|
|
348
|
+
};
|
|
349
|
+
function createTransport() {
|
|
350
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
351
|
+
var transport, TransportWebHid, TransportWebUsb;
|
|
352
|
+
return __generator(this, function (_a) {
|
|
353
|
+
switch (_a.label) {
|
|
354
|
+
case 0:
|
|
355
|
+
checkBrowser(navigator.userAgent);
|
|
356
|
+
if (!isWindows(navigator.platform)) return [3 /*break*/, 2];
|
|
357
|
+
// For Windows
|
|
358
|
+
if (!navigator.hid) {
|
|
359
|
+
throw new LedgerError("This browser doesn't have HID enabled. Enable this feature by visiting: chrome://flags/#enable-experimental-web-platform-features");
|
|
360
|
+
}
|
|
361
|
+
TransportWebHid = require('@ledgerhq/hw-transport-webhid').default;
|
|
362
|
+
return [4 /*yield*/, TransportWebHid.create(INTERACTION_TIMEOUT * 1000).catch(handleConnectError)];
|
|
363
|
+
case 1:
|
|
364
|
+
transport = _a.sent();
|
|
365
|
+
return [3 /*break*/, 4];
|
|
366
|
+
case 2:
|
|
367
|
+
TransportWebUsb = require('@ledgerhq/hw-transport-webusb').default;
|
|
368
|
+
return [4 /*yield*/, TransportWebUsb.create(INTERACTION_TIMEOUT * 1000).catch(handleConnectError)];
|
|
369
|
+
case 3:
|
|
370
|
+
transport = _a.sent();
|
|
371
|
+
_a.label = 4;
|
|
372
|
+
case 4: return [2 /*return*/, transport];
|
|
373
|
+
}
|
|
374
|
+
});
|
|
375
|
+
});
|
|
376
|
+
}
|
|
377
|
+
//# sourceMappingURL=LedgerKey.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"LedgerKey.js","sourceRoot":"","sources":["../../../src/key/ledger/LedgerKey.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,6CAAiC;AAEjC,8CAA8B;AAC9B,2BAA0E;AAC1E,8BAA6B;AAC7B,8CAAgD;AAChD,uCAA4C;AAG5C,IAAM,mBAAmB,GAAG,GAAG,CAAC;AAChC,IAAM,oBAAoB,GAAG,OAAO,CAAC;AAWrC;IAAiC,+BAAK;IACpC,qBAAY,OAAe;QAA3B,YACE,kBAAM,OAAO,CAAC,SAEf;QADC,KAAI,CAAC,IAAI,GAAG,aAAa,CAAC;;IAC5B,CAAC;IACH,kBAAC;AAAD,CAAC,AALD,CAAiC,KAAK,GAKrC;AALY,kCAAW;AAOxB;;;GAGG;AACH;IAA+B,6BAAG;IAIhC;;;OAGG;IACH,mBAAoB,SAA2B;QAA/C,YACE,iBAAO,SAER;QAHmB,eAAS,GAAT,SAAS,CAAkB;QANvC,UAAI,GAAa,CAAC,EAAE,EAAE,4BAAc,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;QAQrD,KAA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AAS,CAAC,GAAG,EAAE;wBAClB,MAAM,IAAI,WAAW,CACnB,mIAAmI,CACpI,CAAC;qBACH;oBAEK,eAAe,GAAG,OAAO,CAAC,+BAA+B,CAAC,CAAC,OAAO,CAAC;oBAC7D,qBAAM,eAAe,CAAC,MAAM,CAAC,mBAAmB,GAAG,IAAI,CAAC,CAAC,KAAK,CAAC,kBAAkB,CAAC,EAAA;;oBAA9F,SAAS,GAAG,SAAkF,CAAC;;;oBAGzF,eAAe,GAAG,OAAO,CAAC,+BAA+B,CAAC,CAAC,OAAO,CAAC;oBAC7D,qBAAM,eAAe,CAAC,MAAM,CAAC,mBAAmB,GAAG,IAAI,CAAC,CAAC,KAAK,CAAC,kBAAkB,CAAC,EAAA;;oBAA9F,SAAS,GAAG,SAAkF,CAAC;;wBAEjG,sBAAO,SAAS,EAAC;;;;CAClB"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/** ******************************************************************************
|
|
2
|
+
* (c) 2019 ZondaX GmbH
|
|
3
|
+
* (c) 2016-2017 Ledger
|
|
4
|
+
*
|
|
5
|
+
* Licensed under the Apache License, Version 2.0 (the 'License');
|
|
6
|
+
* you may not use this file except in compliance with the License.
|
|
7
|
+
* You may obtain a copy of the License at
|
|
8
|
+
*
|
|
9
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
*
|
|
11
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
* distributed under the License is distributed on an 'AS IS' BASIS,
|
|
13
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
* See the License for the specific language governing permissions and
|
|
15
|
+
* limitations under the License.
|
|
16
|
+
******************************************************************************* */
|
|
17
|
+
/// <reference types="node" />
|
|
18
|
+
import Transport from '@ledgerhq/hw-transport';
|
|
19
|
+
import { CommonResponse, AppInfoResponse, VersionResponse, PublicKeyResponse, DeviceInfoResponse, SignResponse } from './types';
|
|
20
|
+
export default class InitiaApp {
|
|
21
|
+
private transport;
|
|
22
|
+
private info;
|
|
23
|
+
private version;
|
|
24
|
+
constructor(transport: Transport | null);
|
|
25
|
+
static serializeHRP(hrp: string): Buffer;
|
|
26
|
+
static getBech32FromPK(hrp: string, pk: Buffer): string;
|
|
27
|
+
private validateCompatibility;
|
|
28
|
+
/**
|
|
29
|
+
* @returns CommonResponse | null returns CommonResponse if app is not compatible
|
|
30
|
+
*/
|
|
31
|
+
initialize(): Promise<CommonResponse | null>;
|
|
32
|
+
getInfo(): AppInfoResponse;
|
|
33
|
+
getVersion(): VersionResponse;
|
|
34
|
+
getDeviceInfo(): Promise<DeviceInfoResponse>;
|
|
35
|
+
getPublicKey(path: number[]): Promise<PublicKeyResponse>;
|
|
36
|
+
getAddressAndPubKey(path: number[], hrp: string): Promise<PublicKeyResponse>;
|
|
37
|
+
showAddressAndPubKey(path: number[], hrp: string): Promise<PublicKeyResponse>;
|
|
38
|
+
sign(path: number[], message: Buffer): Promise<SignResponse>;
|
|
39
|
+
}
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/** ******************************************************************************
|
|
3
|
+
* (c) 2019 ZondaX GmbH
|
|
4
|
+
* (c) 2016-2017 Ledger
|
|
5
|
+
*
|
|
6
|
+
* Licensed under the Apache License, Version 2.0 (the 'License');
|
|
7
|
+
* you may not use this file except in compliance with the License.
|
|
8
|
+
* You may obtain a copy of the License at
|
|
9
|
+
*
|
|
10
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
*
|
|
12
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
13
|
+
* distributed under the License is distributed on an 'AS IS' BASIS,
|
|
14
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
15
|
+
* See the License for the specific language governing permissions and
|
|
16
|
+
* limitations under the License.
|
|
17
|
+
******************************************************************************* */
|
|
18
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
19
|
+
if (k2 === undefined) k2 = k;
|
|
20
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
21
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
22
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
23
|
+
}
|
|
24
|
+
Object.defineProperty(o, k2, desc);
|
|
25
|
+
}) : (function(o, m, k, k2) {
|
|
26
|
+
if (k2 === undefined) k2 = k;
|
|
27
|
+
o[k2] = m[k];
|
|
28
|
+
}));
|
|
29
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
30
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
31
|
+
}) : function(o, v) {
|
|
32
|
+
o["default"] = v;
|
|
33
|
+
});
|
|
34
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
35
|
+
if (mod && mod.__esModule) return mod;
|
|
36
|
+
var result = {};
|
|
37
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
38
|
+
__setModuleDefault(result, mod);
|
|
39
|
+
return result;
|
|
40
|
+
};
|
|
41
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
42
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
43
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
44
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
45
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
46
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
47
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
48
|
+
});
|
|
49
|
+
};
|
|
50
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
51
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
52
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
53
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
54
|
+
function step(op) {
|
|
55
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
56
|
+
while (_) try {
|
|
57
|
+
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;
|
|
58
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
59
|
+
switch (op[0]) {
|
|
60
|
+
case 0: case 1: t = op; break;
|
|
61
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
62
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
63
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
64
|
+
default:
|
|
65
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
66
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
67
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
68
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
69
|
+
if (t[2]) _.ops.pop();
|
|
70
|
+
_.trys.pop(); continue;
|
|
71
|
+
}
|
|
72
|
+
op = body.call(thisArg, _);
|
|
73
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
74
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
78
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
79
|
+
};
|
|
80
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
81
|
+
var crypto = __importStar(require("crypto"));
|
|
82
|
+
var ripemd160_1 = __importDefault(require("ripemd160"));
|
|
83
|
+
var bech32_1 = require("bech32");
|
|
84
|
+
var device_1 = require("./device");
|
|
85
|
+
var APP_NAME_INITIA = 'Initia';
|
|
86
|
+
var APP_NAME_COSMOS = 'Cosmos';
|
|
87
|
+
var InitiaApp = /** @class */ (function () {
|
|
88
|
+
function InitiaApp(transport) {
|
|
89
|
+
if (!transport) {
|
|
90
|
+
throw new Error('Transport has not been defined');
|
|
91
|
+
}
|
|
92
|
+
this.transport = transport;
|
|
93
|
+
}
|
|
94
|
+
InitiaApp.serializeHRP = function (hrp) {
|
|
95
|
+
if (hrp == null || hrp.length < 3 || hrp.length > 83) {
|
|
96
|
+
throw new Error('Invalid HRP');
|
|
97
|
+
}
|
|
98
|
+
var buf = Buffer.alloc(1 + hrp.length);
|
|
99
|
+
buf.writeUInt8(hrp.length, 0);
|
|
100
|
+
buf.write(hrp, 1);
|
|
101
|
+
return buf;
|
|
102
|
+
};
|
|
103
|
+
InitiaApp.getBech32FromPK = function (hrp, pk) {
|
|
104
|
+
if (pk.length !== 33) {
|
|
105
|
+
throw new Error('expected compressed public key [31 bytes]');
|
|
106
|
+
}
|
|
107
|
+
var hashSha256 = crypto.createHash('sha256').update(pk).digest();
|
|
108
|
+
var hashRip = new ripemd160_1.default().update(hashSha256).digest();
|
|
109
|
+
return bech32_1.bech32.encode(hrp, bech32_1.bech32.toWords(hashRip));
|
|
110
|
+
};
|
|
111
|
+
InitiaApp.prototype.validateCompatibility = function () {
|
|
112
|
+
if (this.info && this.version) {
|
|
113
|
+
if (this.info.return_code !== 0x9000) {
|
|
114
|
+
return this.info;
|
|
115
|
+
}
|
|
116
|
+
if (this.version.return_code !== 0x9000) {
|
|
117
|
+
return this.version;
|
|
118
|
+
}
|
|
119
|
+
if ((this.info.app_name === APP_NAME_INITIA && this.version.major === 1) ||
|
|
120
|
+
(this.info.app_name === APP_NAME_COSMOS && this.version.major === 2)) {
|
|
121
|
+
return null;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
return {
|
|
125
|
+
return_code: 0x6400,
|
|
126
|
+
error_message: 'App Version is not supported',
|
|
127
|
+
};
|
|
128
|
+
};
|
|
129
|
+
/**
|
|
130
|
+
* @returns CommonResponse | null returns CommonResponse if app is not compatible
|
|
131
|
+
*/
|
|
132
|
+
InitiaApp.prototype.initialize = function () {
|
|
133
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
134
|
+
var _this = this;
|
|
135
|
+
return __generator(this, function (_a) {
|
|
136
|
+
return [2 /*return*/, (0, device_1.getAppInfo)(this.transport)
|
|
137
|
+
.then(function (appInfo) {
|
|
138
|
+
_this.info = appInfo;
|
|
139
|
+
return (0, device_1.getVersion)(_this.transport);
|
|
140
|
+
})
|
|
141
|
+
.then(function (version) {
|
|
142
|
+
_this.version = version;
|
|
143
|
+
return _this.validateCompatibility();
|
|
144
|
+
})];
|
|
145
|
+
});
|
|
146
|
+
});
|
|
147
|
+
};
|
|
148
|
+
InitiaApp.prototype.getInfo = function () {
|
|
149
|
+
return this.info;
|
|
150
|
+
};
|
|
151
|
+
InitiaApp.prototype.getVersion = function () {
|
|
152
|
+
return this.version;
|
|
153
|
+
};
|
|
154
|
+
InitiaApp.prototype.getDeviceInfo = function () {
|
|
155
|
+
return (0, device_1.getDeviceInfo)(this.transport);
|
|
156
|
+
};
|
|
157
|
+
InitiaApp.prototype.getPublicKey = function (path) {
|
|
158
|
+
var result = (0, device_1.serializePath)(path);
|
|
159
|
+
var data = Buffer.concat([InitiaApp.serializeHRP('init'), result]);
|
|
160
|
+
return (0, device_1.publicKey)(this.transport, data);
|
|
161
|
+
};
|
|
162
|
+
InitiaApp.prototype.getAddressAndPubKey = function (path, hrp) {
|
|
163
|
+
var result = (0, device_1.serializePath)(path);
|
|
164
|
+
var data = Buffer.concat([InitiaApp.serializeHRP(hrp), result]);
|
|
165
|
+
return (0, device_1.getAddressAndPubKey)(this.transport, data);
|
|
166
|
+
};
|
|
167
|
+
InitiaApp.prototype.showAddressAndPubKey = function (path, hrp) {
|
|
168
|
+
var result = (0, device_1.serializePath)(path);
|
|
169
|
+
var data = Buffer.concat([InitiaApp.serializeHRP(hrp), result]);
|
|
170
|
+
return (0, device_1.showAddressAndPubKey)(this.transport, data);
|
|
171
|
+
};
|
|
172
|
+
InitiaApp.prototype.sign = function (path, message) {
|
|
173
|
+
return (0, device_1.sign)(this.transport, path, message);
|
|
174
|
+
};
|
|
175
|
+
return InitiaApp;
|
|
176
|
+
}());
|
|
177
|
+
exports.default = InitiaApp;
|
|
178
|
+
//# sourceMappingURL=app.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"app.js","sourceRoot":"","sources":["../../../src/key/ledger/app.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;mFAemF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEnF,6CAAiC;AACjC,wDAAkC;AAElC,iCAAgC;AAChC,mCASkB;AAUlB,IAAM,eAAe,GAAG,QAAQ,CAAC;AACjC,IAAM,eAAe,GAAG,QAAQ,CAAC;AAEjC;IAKE,mBAAY,SAA2B;QACrC,IAAI,CAAC,SAAS,EAAE;YACd,MAAM,IAAI,KAAK,CAAC,gCAAgC,CAAC,CAAC;SACnD;QAED,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;IAC7B,CAAC;IAEM,sBAAY,GAAnB,UAAoB,GAAW;QAC7B,IAAI,GAAG,IAAI,IAAI,IAAI,GAAG,CAAC,MAAM,GAAG,CAAC,IAAI,GAAG,CAAC,MAAM,GAAG,EAAE,EAAE;YACpD,MAAM,IAAI,KAAK,CAAC,aAAa,CAAC,CAAC;SAChC;QACD,IAAM,GAAG,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC,GAAG,GAAG,CAAC,MAAM,CAAC,CAA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AI,CAAC,SAAS,EAAE,IAAI,CAAC,CAAC;IACnD,CAAC;IAED,wCAAoB,GAApB,UAAqB,IAAc,EAAE,GAAW;QAC9C,IAAM,MAAM,GAAG,IAAA,sBAAa,EAAC,IAAI,CAAC,CAAC;QACnC,IAAM,IAAI,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC,SAAS,CAAC,YAAY,CAAC,GAAG,CAAC,EAAE,MAAM,CAAC,CAAC,CAAC;QAClE,OAAO,IAAA,6BAAoB,EAAC,IAAI,CAAC,SAAS,EAAE,IAAI,CAAC,CAAC;IACpD,CAAC;IAED,wBAAI,GAAJ,UAAK,IAAc,EAAE,OAAe;QAClC,OAAO,IAAA,aAAI,EAAC,IAAI,CAAC,SAAS,EAAE,IAAI,EAAE,OAAO,CAAC,CAAC;IAC7C,CAAC;IACH,gBAAC;AAAD,CAAC,AAxGD,IAwGC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export declare const CLA = 85;
|
|
2
|
+
export declare const CHUNK_SIZE = 250;
|
|
3
|
+
export declare const APP_KEY = "CSM";
|
|
4
|
+
export declare const INS: {
|
|
5
|
+
GET_VERSION: number;
|
|
6
|
+
INS_PUBLIC_KEY_SECP256K1: number;
|
|
7
|
+
SIGN_SECP256K1: number;
|
|
8
|
+
GET_ADDR_SECP256K1: number;
|
|
9
|
+
};
|
|
10
|
+
export declare const PAYLOAD_TYPE: {
|
|
11
|
+
INIT: number;
|
|
12
|
+
ADD: number;
|
|
13
|
+
LAST: number;
|
|
14
|
+
};
|
|
15
|
+
export declare const P1_VALUES: {
|
|
16
|
+
ONLY_RETRIEVE: number;
|
|
17
|
+
SHOW_ADDRESS_IN_DEVICE: number;
|
|
18
|
+
};
|
|
19
|
+
export declare const ERROR_CODE: {
|
|
20
|
+
NoError: number;
|
|
21
|
+
};
|
|
22
|
+
export declare const ERROR_DESCRIPTION: {
|
|
23
|
+
[key: number]: string;
|
|
24
|
+
};
|