@gnolang/tm2-js-client 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (77) hide show
  1. package/LICENSE.md +201 -0
  2. package/README.md +78 -0
  3. package/bin/index.d.ts +4 -0
  4. package/bin/index.js +20 -0
  5. package/bin/proto/google/protobuf/any.d.ts +151 -0
  6. package/bin/proto/google/protobuf/any.js +124 -0
  7. package/bin/proto/index.d.ts +2 -0
  8. package/bin/proto/index.js +20 -0
  9. package/bin/proto/tm2/tx.d.ts +540 -0
  10. package/bin/proto/tm2/tx.js +365 -0
  11. package/bin/provider/endpoints.d.ts +28 -0
  12. package/bin/provider/endpoints.js +36 -0
  13. package/bin/provider/index.d.ts +6 -0
  14. package/bin/provider/index.js +22 -0
  15. package/bin/provider/jsonrpc/index.d.ts +1 -0
  16. package/bin/provider/jsonrpc/index.js +17 -0
  17. package/bin/provider/jsonrpc/jsonrpc.d.ts +27 -0
  18. package/bin/provider/jsonrpc/jsonrpc.js +219 -0
  19. package/bin/provider/jsonrpc/jsonrpc.test.d.ts +1 -0
  20. package/bin/provider/jsonrpc/jsonrpc.test.js +374 -0
  21. package/bin/provider/provider.d.ts +86 -0
  22. package/bin/provider/provider.js +2 -0
  23. package/bin/provider/types/abci.d.ts +39 -0
  24. package/bin/provider/types/abci.js +4 -0
  25. package/bin/provider/types/common.d.ts +154 -0
  26. package/bin/provider/types/common.js +2 -0
  27. package/bin/provider/types/index.d.ts +3 -0
  28. package/bin/provider/types/index.js +19 -0
  29. package/bin/provider/types/jsonrpc.d.ts +26 -0
  30. package/bin/provider/types/jsonrpc.js +2 -0
  31. package/bin/provider/utility/index.d.ts +2 -0
  32. package/bin/provider/utility/index.js +18 -0
  33. package/bin/provider/utility/provider.utility.d.ts +28 -0
  34. package/bin/provider/utility/provider.utility.js +194 -0
  35. package/bin/provider/utility/requests.utility.d.ts +33 -0
  36. package/bin/provider/utility/requests.utility.js +74 -0
  37. package/bin/provider/websocket/index.d.ts +1 -0
  38. package/bin/provider/websocket/index.js +17 -0
  39. package/bin/provider/websocket/ws.d.ts +55 -0
  40. package/bin/provider/websocket/ws.js +303 -0
  41. package/bin/provider/websocket/ws.test.d.ts +1 -0
  42. package/bin/provider/websocket/ws.test.js +535 -0
  43. package/bin/services/index.d.ts +2 -0
  44. package/bin/services/index.js +18 -0
  45. package/bin/services/rest/restService.d.ts +4 -0
  46. package/bin/services/rest/restService.js +72 -0
  47. package/bin/services/rest/restService.types.d.ts +6 -0
  48. package/bin/services/rest/restService.types.js +2 -0
  49. package/bin/wallet/index.d.ts +5 -0
  50. package/bin/wallet/index.js +21 -0
  51. package/bin/wallet/key/index.d.ts +1 -0
  52. package/bin/wallet/key/index.js +17 -0
  53. package/bin/wallet/key/key.d.ts +21 -0
  54. package/bin/wallet/key/key.js +102 -0
  55. package/bin/wallet/key/key.test.d.ts +1 -0
  56. package/bin/wallet/key/key.test.js +121 -0
  57. package/bin/wallet/ledger/index.d.ts +1 -0
  58. package/bin/wallet/ledger/index.js +17 -0
  59. package/bin/wallet/ledger/ledger.d.ts +22 -0
  60. package/bin/wallet/ledger/ledger.js +109 -0
  61. package/bin/wallet/signer.d.ts +29 -0
  62. package/bin/wallet/signer.js +2 -0
  63. package/bin/wallet/types/index.d.ts +2 -0
  64. package/bin/wallet/types/index.js +18 -0
  65. package/bin/wallet/types/sign.d.ts +17 -0
  66. package/bin/wallet/types/sign.js +4 -0
  67. package/bin/wallet/types/wallet.d.ts +5 -0
  68. package/bin/wallet/types/wallet.js +2 -0
  69. package/bin/wallet/utility/index.d.ts +1 -0
  70. package/bin/wallet/utility/index.js +17 -0
  71. package/bin/wallet/utility/utility.d.ts +30 -0
  72. package/bin/wallet/utility/utility.js +105 -0
  73. package/bin/wallet/wallet.d.ts +94 -0
  74. package/bin/wallet/wallet.js +340 -0
  75. package/bin/wallet/wallet.test.d.ts +1 -0
  76. package/bin/wallet/wallet.test.js +345 -0
  77. package/package.json +64 -0
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./key"), exports);
@@ -0,0 +1,21 @@
1
+ import { Signer } from '../signer';
2
+ /**
3
+ * KeySigner implements the logic for the private key signer
4
+ */
5
+ export declare class KeySigner implements Signer {
6
+ private readonly privateKey;
7
+ private readonly publicKey;
8
+ private readonly addressPrefix;
9
+ /**
10
+ * Creates a new {@link KeySigner} instance
11
+ * @param {Uint8Array} privateKey the raw Secp256k1 private key
12
+ * @param {Uint8Array} publicKey the raw Secp256k1 public key
13
+ * @param {string} addressPrefix the address prefix
14
+ */
15
+ constructor(privateKey: Uint8Array, publicKey: Uint8Array, addressPrefix?: string);
16
+ getAddress: () => Promise<string>;
17
+ getPublicKey: () => Promise<Uint8Array>;
18
+ getPrivateKey: () => Promise<Uint8Array>;
19
+ signData: (data: Uint8Array) => Promise<Uint8Array>;
20
+ verifySignature: (data: Uint8Array, signature: Uint8Array) => Promise<boolean>;
21
+ }
@@ -0,0 +1,102 @@
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 (g && (g = 0, op[0] && (_ = 0)), _) 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
+ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
39
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
40
+ if (ar || !(i in from)) {
41
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
42
+ ar[i] = from[i];
43
+ }
44
+ }
45
+ return to.concat(ar || Array.prototype.slice.call(from));
46
+ };
47
+ Object.defineProperty(exports, "__esModule", { value: true });
48
+ exports.KeySigner = void 0;
49
+ var amino_1 = require("@cosmjs/amino");
50
+ var crypto_1 = require("@cosmjs/crypto");
51
+ var utility_1 = require("../utility");
52
+ /**
53
+ * KeySigner implements the logic for the private key signer
54
+ */
55
+ var KeySigner = /** @class */ (function () {
56
+ /**
57
+ * Creates a new {@link KeySigner} instance
58
+ * @param {Uint8Array} privateKey the raw Secp256k1 private key
59
+ * @param {Uint8Array} publicKey the raw Secp256k1 public key
60
+ * @param {string} addressPrefix the address prefix
61
+ */
62
+ function KeySigner(privateKey, publicKey, addressPrefix) {
63
+ if (addressPrefix === void 0) { addressPrefix = utility_1.defaultAddressPrefix; }
64
+ var _this = this;
65
+ this.getAddress = function () { return __awaiter(_this, void 0, void 0, function () {
66
+ return __generator(this, function (_a) {
67
+ return [2 /*return*/, (0, amino_1.pubkeyToAddress)((0, amino_1.encodeSecp256k1Pubkey)(crypto_1.Secp256k1.compressPubkey(this.publicKey)), this.addressPrefix)];
68
+ });
69
+ }); };
70
+ this.getPublicKey = function () { return __awaiter(_this, void 0, void 0, function () {
71
+ return __generator(this, function (_a) {
72
+ return [2 /*return*/, this.publicKey];
73
+ });
74
+ }); };
75
+ this.getPrivateKey = function () { return __awaiter(_this, void 0, void 0, function () {
76
+ return __generator(this, function (_a) {
77
+ return [2 /*return*/, this.privateKey];
78
+ });
79
+ }); };
80
+ this.signData = function (data) { return __awaiter(_this, void 0, void 0, function () {
81
+ var signature;
82
+ return __generator(this, function (_a) {
83
+ switch (_a.label) {
84
+ case 0: return [4 /*yield*/, crypto_1.Secp256k1.createSignature((0, crypto_1.sha256)(data), this.privateKey)];
85
+ case 1:
86
+ signature = _a.sent();
87
+ return [2 /*return*/, new Uint8Array(__spreadArray(__spreadArray([], signature.r(32), true), signature.s(32), true))];
88
+ }
89
+ });
90
+ }); };
91
+ this.verifySignature = function (data, signature) { return __awaiter(_this, void 0, void 0, function () {
92
+ return __generator(this, function (_a) {
93
+ return [2 /*return*/, crypto_1.Secp256k1.verifySignature(crypto_1.Secp256k1Signature.fromFixedLength(signature), (0, crypto_1.sha256)(data), this.publicKey)];
94
+ });
95
+ }); };
96
+ this.privateKey = privateKey;
97
+ this.publicKey = publicKey;
98
+ this.addressPrefix = addressPrefix;
99
+ }
100
+ return KeySigner;
101
+ }());
102
+ exports.KeySigner = KeySigner;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,121 @@
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 (g && (g = 0, op[0] && (_ = 0)), _) 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
+ var utility_1 = require("../utility");
40
+ var bip39_1 = require("@cosmjs/crypto/build/bip39");
41
+ var key_1 = require("./key");
42
+ describe('Private Key Signer', function () {
43
+ var generateRandomKeySigner = function (index) { return __awaiter(void 0, void 0, void 0, function () {
44
+ var _a, publicKey, privateKey;
45
+ return __generator(this, function (_b) {
46
+ switch (_b.label) {
47
+ case 0: return [4 /*yield*/, (0, utility_1.generateKeyPair)((0, bip39_1.entropyToMnemonic)((0, utility_1.generateEntropy)()), index ? index : 0)];
48
+ case 1:
49
+ _a = _b.sent(), publicKey = _a.publicKey, privateKey = _a.privateKey;
50
+ return [2 /*return*/, new key_1.KeySigner(privateKey, publicKey)];
51
+ }
52
+ });
53
+ }); };
54
+ test('getAddress', function () { return __awaiter(void 0, void 0, void 0, function () {
55
+ var signer, address;
56
+ return __generator(this, function (_a) {
57
+ switch (_a.label) {
58
+ case 0: return [4 /*yield*/, generateRandomKeySigner()];
59
+ case 1:
60
+ signer = _a.sent();
61
+ return [4 /*yield*/, signer.getAddress()];
62
+ case 2:
63
+ address = _a.sent();
64
+ expect(address.length).toBe(40);
65
+ return [2 /*return*/];
66
+ }
67
+ });
68
+ }); });
69
+ test('getPublicKey', function () { return __awaiter(void 0, void 0, void 0, function () {
70
+ var signer, publicKey;
71
+ return __generator(this, function (_a) {
72
+ switch (_a.label) {
73
+ case 0: return [4 /*yield*/, generateRandomKeySigner()];
74
+ case 1:
75
+ signer = _a.sent();
76
+ return [4 /*yield*/, signer.getPublicKey()];
77
+ case 2:
78
+ publicKey = _a.sent();
79
+ expect(publicKey).not.toBeNull();
80
+ expect(publicKey).toHaveLength(65);
81
+ return [2 /*return*/];
82
+ }
83
+ });
84
+ }); });
85
+ test('getPrivateKey', function () { return __awaiter(void 0, void 0, void 0, function () {
86
+ var signer, privateKey;
87
+ return __generator(this, function (_a) {
88
+ switch (_a.label) {
89
+ case 0: return [4 /*yield*/, generateRandomKeySigner()];
90
+ case 1:
91
+ signer = _a.sent();
92
+ return [4 /*yield*/, signer.getPrivateKey()];
93
+ case 2:
94
+ privateKey = _a.sent();
95
+ expect(privateKey).not.toBeNull();
96
+ expect(privateKey).toHaveLength(32);
97
+ return [2 /*return*/];
98
+ }
99
+ });
100
+ }); });
101
+ test('signData', function () { return __awaiter(void 0, void 0, void 0, function () {
102
+ var rawData, signer, signature, isValid;
103
+ return __generator(this, function (_a) {
104
+ switch (_a.label) {
105
+ case 0:
106
+ rawData = (0, utility_1.stringToUTF8)('random raw data');
107
+ return [4 /*yield*/, generateRandomKeySigner()];
108
+ case 1:
109
+ signer = _a.sent();
110
+ return [4 /*yield*/, signer.signData(rawData)];
111
+ case 2:
112
+ signature = _a.sent();
113
+ return [4 /*yield*/, signer.verifySignature(rawData, signature)];
114
+ case 3:
115
+ isValid = _a.sent();
116
+ expect(isValid).toBe(true);
117
+ return [2 /*return*/];
118
+ }
119
+ });
120
+ }); });
121
+ });
@@ -0,0 +1 @@
1
+ export * from './ledger';
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./ledger"), exports);
@@ -0,0 +1,22 @@
1
+ import { Signer } from '../signer';
2
+ import { LedgerConnector } from '@cosmjs/ledger-amino';
3
+ /**
4
+ * LedgerSigner implements the logic for the Ledger device signer
5
+ */
6
+ export declare class LedgerSigner implements Signer {
7
+ private readonly connector;
8
+ private readonly hdPath;
9
+ private readonly addressPrefix;
10
+ /**
11
+ * Creates a new Ledger device signer instance
12
+ * @param {LedgerConnector} connector the Ledger connector
13
+ * @param {number} accountIndex the desired account index
14
+ * @param {string} addressPrefix the address prefix
15
+ */
16
+ constructor(connector: LedgerConnector, accountIndex: number, addressPrefix?: string);
17
+ getAddress: () => Promise<string>;
18
+ getPublicKey: () => Promise<Uint8Array>;
19
+ getPrivateKey: () => Promise<Uint8Array>;
20
+ signData: (data: Uint8Array) => Promise<Uint8Array>;
21
+ verifySignature: (data: Uint8Array, signature: Uint8Array) => Promise<boolean>;
22
+ }
@@ -0,0 +1,109 @@
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 (g && (g = 0, op[0] && (_ = 0)), _) 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.LedgerSigner = void 0;
40
+ var utility_1 = require("../utility");
41
+ var crypto_1 = require("@cosmjs/crypto");
42
+ var amino_1 = require("@cosmjs/amino");
43
+ /**
44
+ * LedgerSigner implements the logic for the Ledger device signer
45
+ */
46
+ var LedgerSigner = /** @class */ (function () {
47
+ /**
48
+ * Creates a new Ledger device signer instance
49
+ * @param {LedgerConnector} connector the Ledger connector
50
+ * @param {number} accountIndex the desired account index
51
+ * @param {string} addressPrefix the address prefix
52
+ */
53
+ function LedgerSigner(connector, accountIndex, addressPrefix) {
54
+ if (addressPrefix === void 0) { addressPrefix = utility_1.defaultAddressPrefix; }
55
+ var _this = this;
56
+ this.getAddress = function () { return __awaiter(_this, void 0, void 0, function () {
57
+ var compressedPubKey;
58
+ return __generator(this, function (_a) {
59
+ switch (_a.label) {
60
+ case 0:
61
+ if (!this.connector) {
62
+ throw new Error('Ledger not connected');
63
+ }
64
+ return [4 /*yield*/, this.connector.getPubkey(this.hdPath)];
65
+ case 1:
66
+ compressedPubKey = _a.sent();
67
+ return [2 /*return*/, (0, amino_1.pubkeyToAddress)((0, amino_1.encodeSecp256k1Pubkey)(compressedPubKey), this.addressPrefix)];
68
+ }
69
+ });
70
+ }); };
71
+ this.getPublicKey = function () { return __awaiter(_this, void 0, void 0, function () {
72
+ return __generator(this, function (_a) {
73
+ if (!this.connector) {
74
+ throw new Error('Ledger not connected');
75
+ }
76
+ return [2 /*return*/, this.connector.getPubkey(this.hdPath)];
77
+ });
78
+ }); };
79
+ this.getPrivateKey = function () { return __awaiter(_this, void 0, void 0, function () {
80
+ return __generator(this, function (_a) {
81
+ throw new Error('Ledger does not support private key exports');
82
+ });
83
+ }); };
84
+ this.signData = function (data) { return __awaiter(_this, void 0, void 0, function () {
85
+ return __generator(this, function (_a) {
86
+ if (!this.connector) {
87
+ throw new Error('Ledger not connected');
88
+ }
89
+ return [2 /*return*/, this.connector.sign(data, this.hdPath)];
90
+ });
91
+ }); };
92
+ this.verifySignature = function (data, signature) { return __awaiter(_this, void 0, void 0, function () {
93
+ var publicKey;
94
+ return __generator(this, function (_a) {
95
+ switch (_a.label) {
96
+ case 0: return [4 /*yield*/, this.getPublicKey()];
97
+ case 1:
98
+ publicKey = _a.sent();
99
+ return [2 /*return*/, crypto_1.Secp256k1.verifySignature(crypto_1.Secp256k1Signature.fromFixedLength(signature), (0, crypto_1.sha256)(data), publicKey)];
100
+ }
101
+ });
102
+ }); };
103
+ this.connector = connector;
104
+ this.hdPath = (0, utility_1.generateHDPath)(accountIndex);
105
+ this.addressPrefix = addressPrefix;
106
+ }
107
+ return LedgerSigner;
108
+ }());
109
+ exports.LedgerSigner = LedgerSigner;
@@ -0,0 +1,29 @@
1
+ /**
2
+ * Signer is the base signer API.
3
+ * The signer manages data signing
4
+ */
5
+ export interface Signer {
6
+ /**
7
+ * Returns the address associated with the signer's public key
8
+ */
9
+ getAddress(): Promise<string>;
10
+ /**
11
+ * Returns the signer's Secp256k1-compressed public key
12
+ */
13
+ getPublicKey(): Promise<Uint8Array>;
14
+ /**
15
+ * Returns the signer's actual raw private key
16
+ */
17
+ getPrivateKey(): Promise<Uint8Array>;
18
+ /**
19
+ * Generates a data signature for arbitrary input
20
+ * @param {Uint8Array} data the data to be signed
21
+ */
22
+ signData(data: Uint8Array): Promise<Uint8Array>;
23
+ /**
24
+ * Verifies if the signature matches the provided raw data
25
+ * @param {Uint8Array} data the raw data (not-hashed)
26
+ * @param {Uint8Array} signature the hashed-data signature
27
+ */
28
+ verifySignature(data: Uint8Array, signature: Uint8Array): Promise<boolean>;
29
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,2 @@
1
+ export * from './sign';
2
+ export * from './wallet';
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./sign"), exports);
18
+ __exportStar(require("./wallet"), exports);
@@ -0,0 +1,17 @@
1
+ /**
2
+ * The transaction payload that is signed to generate
3
+ * a valid transaction signature
4
+ */
5
+ export interface TxSignPayload {
6
+ chain_id: string;
7
+ account_number: string;
8
+ sequence: string;
9
+ fee: {
10
+ gas_fee: string;
11
+ gas_wanted: string;
12
+ };
13
+ msgs: any[];
14
+ memo: string;
15
+ time: string;
16
+ }
17
+ export declare const Secp256k1PubKeyType = "/tm.PubKeySecp256k1";
@@ -0,0 +1,4 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Secp256k1PubKeyType = void 0;
4
+ exports.Secp256k1PubKeyType = '/tm.PubKeySecp256k1';
@@ -0,0 +1,5 @@
1
+ export interface CreateWalletOptions {
2
+ addressPrefix?: string;
3
+ accountIndex?: number;
4
+ }
5
+ export type AccountWalletOption = Pick<CreateWalletOptions, 'addressPrefix'>;
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1 @@
1
+ export * from './utility';
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./utility"), exports);
@@ -0,0 +1,30 @@
1
+ import { HdPath } from '@cosmjs/crypto';
2
+ /**
3
+ * Generates the HD path, for the specified index, in the form 'm/44'/118'/0'/0/i',
4
+ * where 'i' is the account index
5
+ * @param {number} [index=0] the account index
6
+ */
7
+ export declare const generateHDPath: (index?: number) => HdPath;
8
+ /**
9
+ * Generates random entropy of the specified size (in B)
10
+ * @param {number} [size=32] the entropy size in bytes
11
+ */
12
+ export declare const generateEntropy: (size?: number) => Uint8Array;
13
+ interface keyPair {
14
+ privateKey: Uint8Array;
15
+ publicKey: Uint8Array;
16
+ }
17
+ /**
18
+ * Generates a new Secp256k1 key-pair using
19
+ * the provided English mnemonic and account index
20
+ * @param {string} mnemonic the English mnemonic
21
+ * @param {number} [accountIndex=0] the account index
22
+ */
23
+ export declare const generateKeyPair: (mnemonic: string, accountIndex?: number) => Promise<keyPair>;
24
+ export declare const defaultAddressPrefix = "g";
25
+ /**
26
+ * Encodes a string into a Uint8Array
27
+ * @param {string} str the string to be encoded
28
+ */
29
+ export declare const stringToUTF8: (str: string) => Uint8Array;
30
+ export {};