@initia/initia.js 0.0.31 → 0.0.33
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/api/IbcAPI.d.ts +6 -0
- package/dist/client/lcd/api/IbcAPI.js +18 -0
- package/dist/client/lcd/api/IbcAPI.js.map +1 -1
- package/dist/client/lcd/api/IbcTransferAPI.d.ts +3 -1
- package/dist/client/lcd/api/IbcTransferAPI.js +12 -1
- package/dist/client/lcd/api/IbcTransferAPI.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/ibc/applications/fee/index.d.ts +2 -1
- package/dist/core/ibc/applications/fee/index.js +2 -1
- package/dist/core/ibc/applications/fee/index.js.map +1 -1
- package/dist/core/ibc/applications/fee/msgs/MsgRegisterCounterpartyPayee.d.ts +37 -0
- package/dist/core/ibc/applications/fee/msgs/MsgRegisterCounterpartyPayee.js +86 -0
- package/dist/core/ibc/applications/fee/msgs/MsgRegisterCounterpartyPayee.js.map +1 -0
- package/dist/core/ibc/applications/fee/msgs/MsgRegisterPayee.d.ts +37 -0
- package/dist/core/ibc/applications/fee/msgs/MsgRegisterPayee.js +86 -0
- package/dist/core/ibc/applications/fee/msgs/MsgRegisterPayee.js.map +1 -0
- package/dist/core/ibc/applications/transfer/v1/msgs/MsgTransfer.d.ts +5 -1
- package/dist/core/ibc/applications/transfer/v1/msgs/MsgTransfer.js +14 -9
- package/dist/core/ibc/applications/transfer/v1/msgs/MsgTransfer.js.map +1 -1
- package/dist/core/ibc/applications/transfer/v2/FungibleTokenPacketData.d.ts +5 -1
- package/dist/core/ibc/applications/transfer/v2/FungibleTokenPacketData.js +14 -9
- package/dist/core/ibc/applications/transfer/v2/FungibleTokenPacketData.js.map +1 -1
- 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/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,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":"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"}
|
|
@@ -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
|
+
};
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ERROR_DESCRIPTION = exports.ERROR_CODE = exports.P1_VALUES = exports.PAYLOAD_TYPE = exports.INS = exports.APP_KEY = exports.CHUNK_SIZE = exports.CLA = void 0;
|
|
4
|
+
exports.CLA = 0x55;
|
|
5
|
+
exports.CHUNK_SIZE = 250;
|
|
6
|
+
exports.APP_KEY = 'CSM';
|
|
7
|
+
exports.INS = {
|
|
8
|
+
GET_VERSION: 0x00,
|
|
9
|
+
INS_PUBLIC_KEY_SECP256K1: 0x01,
|
|
10
|
+
SIGN_SECP256K1: 0x02,
|
|
11
|
+
GET_ADDR_SECP256K1: 0x04,
|
|
12
|
+
};
|
|
13
|
+
exports.PAYLOAD_TYPE = {
|
|
14
|
+
INIT: 0x00,
|
|
15
|
+
ADD: 0x01,
|
|
16
|
+
LAST: 0x02,
|
|
17
|
+
};
|
|
18
|
+
exports.P1_VALUES = {
|
|
19
|
+
ONLY_RETRIEVE: 0x00,
|
|
20
|
+
SHOW_ADDRESS_IN_DEVICE: 0x01,
|
|
21
|
+
};
|
|
22
|
+
exports.ERROR_CODE = {
|
|
23
|
+
NoError: 0x9000,
|
|
24
|
+
};
|
|
25
|
+
exports.ERROR_DESCRIPTION = {
|
|
26
|
+
1: 'U2F: Unknown',
|
|
27
|
+
2: 'U2F: Bad request',
|
|
28
|
+
3: 'U2F: Configuration unsupported',
|
|
29
|
+
4: 'U2F: Device Ineligible',
|
|
30
|
+
5: 'U2F: Timeout',
|
|
31
|
+
14: 'Timeout',
|
|
32
|
+
0x9000: 'No errors',
|
|
33
|
+
0x9001: 'Device is busy',
|
|
34
|
+
0x6802: 'Error deriving keys',
|
|
35
|
+
0x6400: 'Execution Error',
|
|
36
|
+
0x6700: 'Wrong Length',
|
|
37
|
+
0x6982: 'Empty Buffer',
|
|
38
|
+
0x6983: 'Output buffer too small',
|
|
39
|
+
0x6984: 'Data is invalid',
|
|
40
|
+
0x6985: 'Conditions not satisfied',
|
|
41
|
+
0x6986: 'Transaction rejected',
|
|
42
|
+
0x6a80: 'Bad key handle',
|
|
43
|
+
0x6b00: 'Invalid P1/P2',
|
|
44
|
+
0x6b0c: 'Ledger is locked',
|
|
45
|
+
0x6d00: 'Instruction not supported',
|
|
46
|
+
0x6e00: 'App does not seem to be open',
|
|
47
|
+
0x6f00: 'Unknown error',
|
|
48
|
+
0x6f01: 'Sign/verify error',
|
|
49
|
+
};
|
|
50
|
+
//# sourceMappingURL=constants.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../../src/key/ledger/constants.ts"],"names":[],"mappings":";;;AAAa,QAAA,GAAG,GAAG,IAAI,CAAC;AACX,QAAA,UAAU,GAAG,GAAG,CAAC;AACjB,QAAA,OAAO,GAAG,KAAK,CAAC;AAEhB,QAAA,GAAG,GAAG;IACjB,WAAW,EAAE,IAAI;IACjB,wBAAwB,EAAE,IAAI;IAC9B,cAAc,EAAE,IAAI;IACpB,kBAAkB,EAAE,IAAI;CACzB,CAAC;AAEW,QAAA,YAAY,GAAG;IAC1B,IAAI,EAAE,IAAI;IACV,GAAG,EAAE,IAAI;IACT,IAAI,EAAE,IAAI;CACX,CAAC;AAEW,QAAA,SAAS,GAAG;IACvB,aAAa,EAAE,IAAI;IACnB,sBAAsB,EAAE,IAAI;CAC7B,CAAC;AAEW,QAAA,UAAU,GAAG;IACxB,OAAO,EAAE,MAAM;CAChB,CAAC;AAEW,QAAA,iBAAiB,GAA8B;IAC1D,CAAC,EAAE,cAAc;IACjB,CAAC,EAAE,kBAAkB;IACrB,CAAC,EAAE,gCAAgC;IACnC,CAAC,EAAE,wBAAwB;IAC3B,CAAC,EAAE,cAAc;IACjB,EAAE,EAAE,SAAS;IACb,MAAM,EAAE,WAAW;IACnB,MAAM,EAAE,gBAAgB;IACxB,MAAM,EAAE,qBAAqB;IAC7B,MAAM,EAAE,iBAAiB;IACzB,MAAM,EAAE,cAAc;IACtB,MAAM,EAAE,cAAc;IACtB,MAAM,EAAE,yBAAyB;IACjC,MAAM,EAAE,iBAAiB;IACzB,MAAM,EAAE,0BAA0B;IAClC,MAAM,EAAE,sBAAsB;IAC9B,MAAM,EAAE,gBAAgB;IACxB,MAAM,EAAE,eAAe;IACvB,MAAM,EAAE,kBAAkB;IAC1B,MAAM,EAAE,2BAA2B;IACnC,MAAM,EAAE,8BAA8B;IACtC,MAAM,EAAE,eAAe;IACvB,MAAM,EAAE,mBAAmB;CAC5B,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import Transport from '@ledgerhq/hw-transport';
|
|
3
|
+
import { AppInfoResponse, VersionResponse, DeviceInfoResponse, PublicKeyResponse, SignResponse } from './types';
|
|
4
|
+
export declare function serializePath(path: number[]): Buffer;
|
|
5
|
+
export declare function getVersion(transport: Transport): Promise<VersionResponse>;
|
|
6
|
+
export declare function getAppInfo(transport: Transport): Promise<AppInfoResponse>;
|
|
7
|
+
export declare function getDeviceInfo(transport: Transport): Promise<DeviceInfoResponse>;
|
|
8
|
+
export declare function publicKey(transport: Transport, data: Buffer): Promise<PublicKeyResponse>;
|
|
9
|
+
export declare function getAddressAndPubKey(transport: Transport, data: Buffer): Promise<PublicKeyResponse>;
|
|
10
|
+
export declare function showAddressAndPubKey(transport: Transport, data: Buffer): Promise<PublicKeyResponse>;
|
|
11
|
+
export declare function sign(transport: Transport, path: number[], message: Buffer): Promise<SignResponse>;
|
|
@@ -0,0 +1,379 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
13
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
+
function step(op) {
|
|
16
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
+
while (_) try {
|
|
18
|
+
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;
|
|
19
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
+
switch (op[0]) {
|
|
21
|
+
case 0: case 1: t = op; break;
|
|
22
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
+
default:
|
|
26
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
+
if (t[2]) _.ops.pop();
|
|
31
|
+
_.trys.pop(); continue;
|
|
32
|
+
}
|
|
33
|
+
op = body.call(thisArg, _);
|
|
34
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
exports.sign = exports.showAddressAndPubKey = exports.getAddressAndPubKey = exports.publicKey = exports.getDeviceInfo = exports.getAppInfo = exports.getVersion = exports.serializePath = void 0;
|
|
40
|
+
var constants_1 = require("./constants");
|
|
41
|
+
function errorCodeToString(statusCode) {
|
|
42
|
+
if (statusCode in constants_1.ERROR_DESCRIPTION) {
|
|
43
|
+
return constants_1.ERROR_DESCRIPTION[statusCode];
|
|
44
|
+
}
|
|
45
|
+
return "Unknown Status Code: ".concat(statusCode);
|
|
46
|
+
}
|
|
47
|
+
function isDict(v) {
|
|
48
|
+
return typeof v === 'object' && v !== null && !(v instanceof Array) && !(v instanceof Date);
|
|
49
|
+
}
|
|
50
|
+
function processErrorResponse(response) {
|
|
51
|
+
if (response) {
|
|
52
|
+
if (isDict(response)) {
|
|
53
|
+
if (Object.prototype.hasOwnProperty.call(response, 'statusCode')) {
|
|
54
|
+
return {
|
|
55
|
+
return_code: response.statusCode,
|
|
56
|
+
error_message: errorCodeToString(response.statusCode),
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
if (Object.prototype.hasOwnProperty.call(response, 'return_code') &&
|
|
60
|
+
Object.prototype.hasOwnProperty.call(response, 'error_message')) {
|
|
61
|
+
return response;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
return {
|
|
65
|
+
return_code: 0xffff,
|
|
66
|
+
error_message: response.toString(),
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
return {
|
|
70
|
+
return_code: 0xffff,
|
|
71
|
+
error_message: response.toString(),
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
function serializePath(path) {
|
|
75
|
+
if (!path || path.length !== 5) {
|
|
76
|
+
throw new TypeError('Invalid path.');
|
|
77
|
+
}
|
|
78
|
+
var buf = Buffer.alloc(20);
|
|
79
|
+
buf.writeUInt32LE(0x80000000 + path[0], 0);
|
|
80
|
+
buf.writeUInt32LE(0x80000000 + path[1], 4);
|
|
81
|
+
buf.writeUInt32LE(0x80000000 + path[2], 8);
|
|
82
|
+
buf.writeUInt32LE(path[3], 12);
|
|
83
|
+
buf.writeUInt32LE(path[4], 16);
|
|
84
|
+
return buf;
|
|
85
|
+
}
|
|
86
|
+
exports.serializePath = serializePath;
|
|
87
|
+
function getVersion(transport) {
|
|
88
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
89
|
+
return __generator(this, function (_a) {
|
|
90
|
+
return [2 /*return*/, transport
|
|
91
|
+
.send(constants_1.CLA, constants_1.INS.GET_VERSION, 0, 0)
|
|
92
|
+
.then(function (response) {
|
|
93
|
+
var errorCodeData = response.slice(-2);
|
|
94
|
+
var return_code = errorCodeData[0] * 256 + errorCodeData[1];
|
|
95
|
+
var targetId = 0;
|
|
96
|
+
if (response.length >= 9) {
|
|
97
|
+
/* eslint-disable no-bitwise */
|
|
98
|
+
targetId = (response[5] << 24) + (response[6] << 16) + (response[7] << 8) + (response[8] << 0);
|
|
99
|
+
/* eslint-enable no-bitwise */
|
|
100
|
+
}
|
|
101
|
+
return {
|
|
102
|
+
return_code: return_code,
|
|
103
|
+
error_message: errorCodeToString(return_code),
|
|
104
|
+
// ///
|
|
105
|
+
test_mode: response[0] !== 0,
|
|
106
|
+
major: response[1],
|
|
107
|
+
minor: response[2],
|
|
108
|
+
patch: response[3],
|
|
109
|
+
device_locked: response[4] === 1,
|
|
110
|
+
target_id: targetId.toString(16),
|
|
111
|
+
};
|
|
112
|
+
})
|
|
113
|
+
.catch(processErrorResponse)];
|
|
114
|
+
});
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
exports.getVersion = getVersion;
|
|
118
|
+
function getAppInfo(transport) {
|
|
119
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
120
|
+
return __generator(this, function (_a) {
|
|
121
|
+
return [2 /*return*/, transport
|
|
122
|
+
.send(0xb0, 0x01, 0, 0)
|
|
123
|
+
.then(function (response) {
|
|
124
|
+
var errorCodeData = response.slice(-2);
|
|
125
|
+
var return_code = errorCodeData[0] * 256 + errorCodeData[1];
|
|
126
|
+
var error_message;
|
|
127
|
+
var app_name = 'err';
|
|
128
|
+
var app_version = 'err';
|
|
129
|
+
var flag_len = 0;
|
|
130
|
+
var flags_value = 0;
|
|
131
|
+
if (response[0] !== 1) {
|
|
132
|
+
// Ledger responds with format ID 1. There is no spec for any format != 1
|
|
133
|
+
error_message = 'response format ID not recognized';
|
|
134
|
+
return_code = 0x9001;
|
|
135
|
+
}
|
|
136
|
+
else {
|
|
137
|
+
error_message = 'No errors';
|
|
138
|
+
var appNameLen = response[1];
|
|
139
|
+
app_name = response.slice(2, 2 + appNameLen).toString('ascii');
|
|
140
|
+
var idx = 2 + appNameLen;
|
|
141
|
+
var appVersionLen = response[idx];
|
|
142
|
+
idx += 1;
|
|
143
|
+
app_version = response.slice(idx, idx + appVersionLen).toString('ascii');
|
|
144
|
+
idx += appVersionLen;
|
|
145
|
+
var appFlagsLen = response[idx];
|
|
146
|
+
idx += 1;
|
|
147
|
+
flag_len = appFlagsLen;
|
|
148
|
+
flags_value = response[idx];
|
|
149
|
+
}
|
|
150
|
+
return {
|
|
151
|
+
return_code: return_code,
|
|
152
|
+
error_message: error_message,
|
|
153
|
+
// //
|
|
154
|
+
app_name: app_name,
|
|
155
|
+
app_version: app_version,
|
|
156
|
+
flag_len: flag_len,
|
|
157
|
+
flags_value: flags_value,
|
|
158
|
+
// eslint-disable-next-line no-bitwise
|
|
159
|
+
flag_recovery: (flags_value & 1) !== 0,
|
|
160
|
+
// eslint-disable-next-line no-bitwise
|
|
161
|
+
flag_signed_mcu_code: (flags_value & 2) !== 0,
|
|
162
|
+
// eslint-disable-next-line no-bitwise
|
|
163
|
+
flag_onboarded: (flags_value & 4) !== 0,
|
|
164
|
+
// eslint-disable-next-line no-bitwise
|
|
165
|
+
flag_pin_validated: (flags_value & 128) !== 0,
|
|
166
|
+
};
|
|
167
|
+
})
|
|
168
|
+
.catch(processErrorResponse)];
|
|
169
|
+
});
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
exports.getAppInfo = getAppInfo;
|
|
173
|
+
function getDeviceInfo(transport) {
|
|
174
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
175
|
+
return __generator(this, function (_a) {
|
|
176
|
+
return [2 /*return*/, transport
|
|
177
|
+
.send(0xe0, 0x01, 0, 0, Buffer.from([]), [constants_1.ERROR_CODE.NoError, 0x6e00])
|
|
178
|
+
.then(function (response) {
|
|
179
|
+
var errorCodeData = response.slice(-2);
|
|
180
|
+
var returnCode = errorCodeData[0] * 256 + errorCodeData[1];
|
|
181
|
+
if (returnCode === 0x6e00) {
|
|
182
|
+
return {
|
|
183
|
+
return_code: returnCode,
|
|
184
|
+
error_message: 'This command is only available in the Dashboard',
|
|
185
|
+
};
|
|
186
|
+
}
|
|
187
|
+
var target_id = response.slice(0, 4).toString('hex');
|
|
188
|
+
var pos = 4;
|
|
189
|
+
var secureElementVersionLen = response[pos];
|
|
190
|
+
pos += 1;
|
|
191
|
+
var se_version = response.slice(pos, pos + secureElementVersionLen).toString();
|
|
192
|
+
pos += secureElementVersionLen;
|
|
193
|
+
var flagsLen = response[pos];
|
|
194
|
+
pos += 1;
|
|
195
|
+
var flag = response.slice(pos, pos + flagsLen).toString('hex');
|
|
196
|
+
pos += flagsLen;
|
|
197
|
+
var mcuVersionLen = response[pos];
|
|
198
|
+
pos += 1;
|
|
199
|
+
// Patch issue in mcu version
|
|
200
|
+
var tmp = response.slice(pos, pos + mcuVersionLen);
|
|
201
|
+
if (tmp[mcuVersionLen - 1] === 0) {
|
|
202
|
+
tmp = response.slice(pos, pos + mcuVersionLen - 1);
|
|
203
|
+
}
|
|
204
|
+
var mcu_version = tmp.toString();
|
|
205
|
+
return {
|
|
206
|
+
return_code: returnCode,
|
|
207
|
+
error_message: errorCodeToString(returnCode),
|
|
208
|
+
// //
|
|
209
|
+
target_id: target_id,
|
|
210
|
+
se_version: se_version,
|
|
211
|
+
flag: flag,
|
|
212
|
+
mcu_version: mcu_version,
|
|
213
|
+
};
|
|
214
|
+
})
|
|
215
|
+
.catch(processErrorResponse)];
|
|
216
|
+
});
|
|
217
|
+
});
|
|
218
|
+
}
|
|
219
|
+
exports.getDeviceInfo = getDeviceInfo;
|
|
220
|
+
function publicKey(transport, data) {
|
|
221
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
222
|
+
return __generator(this, function (_a) {
|
|
223
|
+
return [2 /*return*/, transport
|
|
224
|
+
.send(constants_1.CLA, constants_1.INS.GET_ADDR_SECP256K1, 0, 0, data, [constants_1.ERROR_CODE.NoError])
|
|
225
|
+
.then(function (response) {
|
|
226
|
+
var errorCodeData = response.slice(-2);
|
|
227
|
+
var returnCode = errorCodeData[0] * 256 + errorCodeData[1];
|
|
228
|
+
var compressedPk = response ? Buffer.from(response.slice(0, 33)) : null;
|
|
229
|
+
return {
|
|
230
|
+
pk: 'OBSOLETE PROPERTY',
|
|
231
|
+
compressed_pk: compressedPk ? compressedPk.toJSON() : compressedPk,
|
|
232
|
+
return_code: returnCode,
|
|
233
|
+
error_message: errorCodeToString(returnCode),
|
|
234
|
+
};
|
|
235
|
+
})
|
|
236
|
+
.catch(processErrorResponse)];
|
|
237
|
+
});
|
|
238
|
+
});
|
|
239
|
+
}
|
|
240
|
+
exports.publicKey = publicKey;
|
|
241
|
+
function getAddressAndPubKey(transport, data) {
|
|
242
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
243
|
+
return __generator(this, function (_a) {
|
|
244
|
+
return [2 /*return*/, transport
|
|
245
|
+
.send(constants_1.CLA, constants_1.INS.GET_ADDR_SECP256K1, constants_1.P1_VALUES.ONLY_RETRIEVE, 0, data, [constants_1.ERROR_CODE.NoError])
|
|
246
|
+
.then(function (response) {
|
|
247
|
+
var errorCodeData = response.slice(-2);
|
|
248
|
+
var returnCode = errorCodeData[0] * 256 + errorCodeData[1];
|
|
249
|
+
var compressedPk = Buffer.from(response.slice(0, 33));
|
|
250
|
+
var bech32Address = Buffer.from(response.slice(33, -2)).toString();
|
|
251
|
+
return {
|
|
252
|
+
bech32_address: bech32Address,
|
|
253
|
+
compressed_pk: compressedPk.toJSON(),
|
|
254
|
+
return_code: returnCode,
|
|
255
|
+
error_message: errorCodeToString(returnCode),
|
|
256
|
+
};
|
|
257
|
+
})
|
|
258
|
+
.catch(processErrorResponse)];
|
|
259
|
+
});
|
|
260
|
+
});
|
|
261
|
+
}
|
|
262
|
+
exports.getAddressAndPubKey = getAddressAndPubKey;
|
|
263
|
+
function showAddressAndPubKey(transport, data) {
|
|
264
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
265
|
+
return __generator(this, function (_a) {
|
|
266
|
+
return [2 /*return*/, transport
|
|
267
|
+
.send(constants_1.CLA, constants_1.INS.GET_ADDR_SECP256K1, constants_1.P1_VALUES.SHOW_ADDRESS_IN_DEVICE, 0, data, [constants_1.ERROR_CODE.NoError])
|
|
268
|
+
.then(function (response) {
|
|
269
|
+
var errorCodeData = response.slice(-2);
|
|
270
|
+
var returnCode = errorCodeData[0] * 256 + errorCodeData[1];
|
|
271
|
+
var compressedPk = Buffer.from(response.slice(0, 33));
|
|
272
|
+
var bech32Address = Buffer.from(response.slice(33, -2)).toString();
|
|
273
|
+
return {
|
|
274
|
+
bech32_address: bech32Address,
|
|
275
|
+
compressed_pk: compressedPk.toJSON(),
|
|
276
|
+
return_code: returnCode,
|
|
277
|
+
error_message: errorCodeToString(returnCode),
|
|
278
|
+
};
|
|
279
|
+
})
|
|
280
|
+
.catch(processErrorResponse)];
|
|
281
|
+
});
|
|
282
|
+
});
|
|
283
|
+
}
|
|
284
|
+
exports.showAddressAndPubKey = showAddressAndPubKey;
|
|
285
|
+
function signGetChunks(path, message) {
|
|
286
|
+
var result = serializePath(path);
|
|
287
|
+
var chunks = [];
|
|
288
|
+
if (result instanceof Buffer) {
|
|
289
|
+
chunks.push(result);
|
|
290
|
+
var buffer = Buffer.from(message);
|
|
291
|
+
for (var i = 0; i < buffer.length; i += constants_1.CHUNK_SIZE) {
|
|
292
|
+
var end = i + constants_1.CHUNK_SIZE;
|
|
293
|
+
if (i > buffer.length) {
|
|
294
|
+
end = buffer.length;
|
|
295
|
+
}
|
|
296
|
+
chunks.push(buffer.slice(i, end));
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
return chunks;
|
|
300
|
+
}
|
|
301
|
+
function signSendChunk(transport, chunkIdx, chunkNum, chunk) {
|
|
302
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
303
|
+
var payloadType;
|
|
304
|
+
return __generator(this, function (_a) {
|
|
305
|
+
payloadType = constants_1.PAYLOAD_TYPE.ADD;
|
|
306
|
+
if (chunkIdx === 1) {
|
|
307
|
+
payloadType = constants_1.PAYLOAD_TYPE.INIT;
|
|
308
|
+
}
|
|
309
|
+
if (chunkIdx === chunkNum) {
|
|
310
|
+
payloadType = constants_1.PAYLOAD_TYPE.LAST;
|
|
311
|
+
}
|
|
312
|
+
return [2 /*return*/, transport
|
|
313
|
+
.send(constants_1.CLA, constants_1.INS.SIGN_SECP256K1, payloadType, 0, chunk, [constants_1.ERROR_CODE.NoError, 0x6984, 0x6a80])
|
|
314
|
+
.then(function (response) {
|
|
315
|
+
var errorCodeData = response.slice(-2);
|
|
316
|
+
var returnCode = errorCodeData[0] * 256 + errorCodeData[1];
|
|
317
|
+
var errorMessage = errorCodeToString(returnCode);
|
|
318
|
+
if (returnCode === 0x6a80 || returnCode === 0x6984) {
|
|
319
|
+
errorMessage = "".concat(errorMessage, " : ").concat(response.slice(0, response.length - 2).toString('ascii'));
|
|
320
|
+
}
|
|
321
|
+
var signature = Buffer.from([]);
|
|
322
|
+
if (response.length > 2) {
|
|
323
|
+
signature = response.slice(0, response.length - 2);
|
|
324
|
+
}
|
|
325
|
+
return {
|
|
326
|
+
signature: signature.toJSON(),
|
|
327
|
+
return_code: returnCode,
|
|
328
|
+
error_message: errorMessage,
|
|
329
|
+
};
|
|
330
|
+
})
|
|
331
|
+
.catch(processErrorResponse)];
|
|
332
|
+
});
|
|
333
|
+
});
|
|
334
|
+
}
|
|
335
|
+
function sign(transport, path, message) {
|
|
336
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
337
|
+
var chunks;
|
|
338
|
+
var _this = this;
|
|
339
|
+
return __generator(this, function (_a) {
|
|
340
|
+
chunks = signGetChunks(path, message);
|
|
341
|
+
return [2 /*return*/, signSendChunk(transport, 1, chunks.length, chunks[0])
|
|
342
|
+
.then(function (response) { return __awaiter(_this, void 0, void 0, function () {
|
|
343
|
+
var result, i;
|
|
344
|
+
return __generator(this, function (_a) {
|
|
345
|
+
switch (_a.label) {
|
|
346
|
+
case 0:
|
|
347
|
+
result = {
|
|
348
|
+
return_code: response.return_code,
|
|
349
|
+
error_message: response.error_message,
|
|
350
|
+
signature: { type: 'Buffer', data: [] },
|
|
351
|
+
};
|
|
352
|
+
i = 1;
|
|
353
|
+
_a.label = 1;
|
|
354
|
+
case 1:
|
|
355
|
+
if (!(i < chunks.length)) return [3 /*break*/, 4];
|
|
356
|
+
return [4 /*yield*/, signSendChunk(transport, 1 + i, chunks.length, chunks[i])];
|
|
357
|
+
case 2:
|
|
358
|
+
result = _a.sent();
|
|
359
|
+
if (result.return_code !== constants_1.ERROR_CODE.NoError) {
|
|
360
|
+
return [3 /*break*/, 4];
|
|
361
|
+
}
|
|
362
|
+
_a.label = 3;
|
|
363
|
+
case 3:
|
|
364
|
+
i += 1;
|
|
365
|
+
return [3 /*break*/, 1];
|
|
366
|
+
case 4: return [2 /*return*/, {
|
|
367
|
+
return_code: result.return_code,
|
|
368
|
+
error_message: result.error_message,
|
|
369
|
+
signature: result.signature,
|
|
370
|
+
}];
|
|
371
|
+
}
|
|
372
|
+
});
|
|
373
|
+
}); })
|
|
374
|
+
.catch(processErrorResponse)];
|
|
375
|
+
});
|
|
376
|
+
});
|
|
377
|
+
}
|
|
378
|
+
exports.sign = sign;
|
|
379
|
+
//# sourceMappingURL=device.js.map
|