@firmachain/firma-js 0.2.31 → 0.2.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/sdk/FirmaAuthzService.d.ts +13 -4
- package/dist/sdk/FirmaAuthzService.js +9 -6
- package/dist/sdk/FirmaIbcService.d.ts +15 -0
- package/dist/sdk/FirmaIbcService.js +144 -0
- package/dist/sdk/FirmaSDK.d.ts +3 -1
- package/dist/sdk/FirmaSDK.js +4 -1
- package/dist/sdk/FirmaStakingService.d.ts +17 -5
- package/dist/sdk/FirmaStakingService.js +12 -8
- package/dist/sdk/FirmaUtil.d.ts +6 -0
- package/dist/sdk/FirmaUtil.js +64 -0
- package/dist/sdk/FirmaWalletService.d.ts +3 -0
- package/dist/sdk/FirmaWalletService.js +18 -10
- package/dist/sdk/firmachain/amino/signer.d.ts +1 -2
- package/dist/sdk/firmachain/authz/AuthzQueryClient.d.ts +13 -3
- package/dist/sdk/firmachain/authz/AuthzQueryClient.js +39 -12
- package/dist/sdk/firmachain/common/signingaminostargateclient.d.ts +50 -0
- package/dist/sdk/firmachain/common/signingaminostargateclient.js +267 -0
- package/dist/sdk/firmachain/ibc/IbcQueryClient.d.ts +34 -0
- package/dist/sdk/firmachain/ibc/IbcQueryClient.js +71 -0
- package/dist/sdk/firmachain/ibc/IbcTxClient.d.ts +12 -0
- package/dist/sdk/firmachain/ibc/IbcTxClient.js +36 -0
- package/dist/sdk/firmachain/ibc/index.d.ts +3 -0
- package/dist/sdk/firmachain/ibc/index.js +15 -0
- package/dist/sdk/firmachain/staking/StakingQueryClient.d.ts +17 -4
- package/dist/sdk/firmachain/staking/StakingQueryClient.js +38 -18
- package/package.json +1 -1
- package/dist/sdk/firmachain/amino/secp256k1hdwallet.d.ts +0 -94
- package/dist/sdk/firmachain/amino/secp256k1hdwallet.js +0 -437
- package/dist/sdk/firmachain/amino/secp256k1wallet.d.ts +0 -23
- package/dist/sdk/firmachain/amino/secp256k1wallet.js +0 -141
|
@@ -113,47 +113,62 @@ var StakingQueryClient = /** @class */ (function () {
|
|
|
113
113
|
});
|
|
114
114
|
});
|
|
115
115
|
};
|
|
116
|
-
StakingQueryClient.prototype.queryGetUndelegationListFromValidator = function (
|
|
116
|
+
StakingQueryClient.prototype.queryGetUndelegationListFromValidator = function (valoperAddress, paginationKey) {
|
|
117
|
+
if (paginationKey === void 0) { paginationKey = ""; }
|
|
117
118
|
return __awaiter(this, void 0, void 0, function () {
|
|
118
|
-
var path, result;
|
|
119
|
+
var path, result, convertPagination;
|
|
119
120
|
return __generator(this, function (_a) {
|
|
120
121
|
switch (_a.label) {
|
|
121
122
|
case 0:
|
|
122
|
-
path = "/cosmos/staking/v1beta1/validators/" +
|
|
123
|
-
return [4 /*yield*/, this.axios.get(path)];
|
|
123
|
+
path = "/cosmos/staking/v1beta1/validators/" + valoperAddress + "/unbonding_delegations";
|
|
124
|
+
return [4 /*yield*/, this.axios.get(path, { params: { "pagination.key": paginationKey } })];
|
|
124
125
|
case 1:
|
|
125
126
|
result = _a.sent();
|
|
126
|
-
|
|
127
|
+
convertPagination = {
|
|
128
|
+
next_key: result.data.pagination.next_key,
|
|
129
|
+
total: Number.parseInt(result.data.pagination.total)
|
|
130
|
+
};
|
|
131
|
+
return [2 /*return*/, { dataList: result.data.unbonding_responses, pagination: convertPagination }];
|
|
127
132
|
}
|
|
128
133
|
});
|
|
129
134
|
});
|
|
130
135
|
};
|
|
131
|
-
StakingQueryClient.prototype.queryGetDelegateListFromValidator = function (
|
|
136
|
+
StakingQueryClient.prototype.queryGetDelegateListFromValidator = function (valoperAddress, paginationKey) {
|
|
137
|
+
if (paginationKey === void 0) { paginationKey = ""; }
|
|
132
138
|
return __awaiter(this, void 0, void 0, function () {
|
|
133
|
-
var path, result;
|
|
139
|
+
var path, result, convertPagination;
|
|
134
140
|
return __generator(this, function (_a) {
|
|
135
141
|
switch (_a.label) {
|
|
136
142
|
case 0:
|
|
137
|
-
path = "/cosmos/staking/v1beta1/validators/" +
|
|
138
|
-
return [4 /*yield*/, this.axios.get(path)];
|
|
143
|
+
path = "/cosmos/staking/v1beta1/validators/" + valoperAddress + "/delegations";
|
|
144
|
+
return [4 /*yield*/, this.axios.get(path, { params: { "pagination.key": paginationKey } })];
|
|
139
145
|
case 1:
|
|
140
146
|
result = _a.sent();
|
|
141
|
-
|
|
147
|
+
convertPagination = {
|
|
148
|
+
next_key: result.data.pagination.next_key,
|
|
149
|
+
total: Number.parseInt(result.data.pagination.total)
|
|
150
|
+
};
|
|
151
|
+
return [2 /*return*/, { dataList: result.data.delegation_responses, pagination: convertPagination }];
|
|
142
152
|
}
|
|
143
153
|
});
|
|
144
154
|
});
|
|
145
155
|
};
|
|
146
|
-
StakingQueryClient.prototype.queryGetTotalDelegationInfo = function (address) {
|
|
156
|
+
StakingQueryClient.prototype.queryGetTotalDelegationInfo = function (address, paginationKey) {
|
|
157
|
+
if (paginationKey === void 0) { paginationKey = ""; }
|
|
147
158
|
return __awaiter(this, void 0, void 0, function () {
|
|
148
|
-
var path, result;
|
|
159
|
+
var path, result, convertPagination;
|
|
149
160
|
return __generator(this, function (_a) {
|
|
150
161
|
switch (_a.label) {
|
|
151
162
|
case 0:
|
|
152
163
|
path = "/cosmos/staking/v1beta1/delegations/" + address;
|
|
153
|
-
return [4 /*yield*/, this.axios.get(path)];
|
|
164
|
+
return [4 /*yield*/, this.axios.get(path, { params: { "pagination.key": paginationKey } })];
|
|
154
165
|
case 1:
|
|
155
166
|
result = _a.sent();
|
|
156
|
-
|
|
167
|
+
convertPagination = {
|
|
168
|
+
next_key: result.data.pagination.next_key,
|
|
169
|
+
total: Number.parseInt(result.data.pagination.total)
|
|
170
|
+
};
|
|
171
|
+
return [2 /*return*/, { dataList: result.data.delegation_responses, pagination: convertPagination }];
|
|
157
172
|
}
|
|
158
173
|
});
|
|
159
174
|
});
|
|
@@ -203,17 +218,22 @@ var StakingQueryClient = /** @class */ (function () {
|
|
|
203
218
|
});
|
|
204
219
|
});
|
|
205
220
|
};
|
|
206
|
-
StakingQueryClient.prototype.queryValidators = function () {
|
|
221
|
+
StakingQueryClient.prototype.queryValidators = function (paginationKey) {
|
|
222
|
+
if (paginationKey === void 0) { paginationKey = ""; }
|
|
207
223
|
return __awaiter(this, void 0, void 0, function () {
|
|
208
|
-
var path, result;
|
|
224
|
+
var path, result, convertPagination;
|
|
209
225
|
return __generator(this, function (_a) {
|
|
210
226
|
switch (_a.label) {
|
|
211
227
|
case 0:
|
|
212
228
|
path = "/cosmos/staking/v1beta1/validators";
|
|
213
|
-
return [4 /*yield*/, this.axios.get(path)];
|
|
229
|
+
return [4 /*yield*/, this.axios.get(path, { params: { "pagination.key": paginationKey } })];
|
|
214
230
|
case 1:
|
|
215
231
|
result = _a.sent();
|
|
216
|
-
|
|
232
|
+
convertPagination = {
|
|
233
|
+
next_key: result.data.pagination.next_key,
|
|
234
|
+
total: Number.parseInt(result.data.pagination.total)
|
|
235
|
+
};
|
|
236
|
+
return [2 /*return*/, { dataList: result.data.validators, pagination: convertPagination }];
|
|
217
237
|
}
|
|
218
238
|
});
|
|
219
239
|
});
|
package/package.json
CHANGED
|
@@ -1,94 +0,0 @@
|
|
|
1
|
-
import { EnglishMnemonic, HdPath } from "@cosmjs/crypto";
|
|
2
|
-
import { StdSignDoc } from "./signdoc";
|
|
3
|
-
import { AccountData, AminoSignResponse, OfflineAminoSigner } from "./signer";
|
|
4
|
-
import { EncryptionConfiguration, KdfConfiguration } from "./wallet";
|
|
5
|
-
/**
|
|
6
|
-
* This interface describes a JSON object holding the encrypted wallet and the meta data.
|
|
7
|
-
* All fields in here must be JSON types.
|
|
8
|
-
*/
|
|
9
|
-
export interface Secp256k1HdWalletSerialization {
|
|
10
|
-
/** A format+version identifier for this serialization format */
|
|
11
|
-
readonly type: string;
|
|
12
|
-
/** Information about the key derivation function (i.e. password to encryption key) */
|
|
13
|
-
readonly kdf: KdfConfiguration;
|
|
14
|
-
/** Information about the symmetric encryption */
|
|
15
|
-
readonly encryption: EncryptionConfiguration;
|
|
16
|
-
/** An instance of Secp256k1HdWalletData, which is stringified, encrypted and base64 encoded. */
|
|
17
|
-
readonly data: string;
|
|
18
|
-
}
|
|
19
|
-
export declare function extractKdfConfiguration(serialization: string): KdfConfiguration;
|
|
20
|
-
export interface Secp256k1HdWalletOptions {
|
|
21
|
-
/** The password to use when deriving a BIP39 seed from a mnemonic. */
|
|
22
|
-
readonly bip39Password: string;
|
|
23
|
-
/** The BIP-32/SLIP-10 derivation paths. Defaults to the Cosmos Hub/ATOM path `m/44'/118'/0'/0/0`. */
|
|
24
|
-
readonly hdPaths: readonly HdPath[];
|
|
25
|
-
/** The bech32 address prefix (human readable part). Defaults to "cosmos". */
|
|
26
|
-
readonly prefix: string;
|
|
27
|
-
}
|
|
28
|
-
interface Secp256k1HdWalletConstructorOptions extends Partial<Secp256k1HdWalletOptions> {
|
|
29
|
-
readonly seed: Uint8Array;
|
|
30
|
-
}
|
|
31
|
-
export declare class Secp256k1HdWallet implements OfflineAminoSigner {
|
|
32
|
-
/**
|
|
33
|
-
* Restores a wallet from the given BIP39 mnemonic.
|
|
34
|
-
*
|
|
35
|
-
* @param mnemonic Any valid English mnemonic.
|
|
36
|
-
* @param options An optional `Secp256k1HdWalletOptions` object optionally containing a bip39Password, hdPaths, and prefix.
|
|
37
|
-
*/
|
|
38
|
-
static fromMnemonic(mnemonic: string, options?: Partial<Secp256k1HdWalletOptions>): Promise<Secp256k1HdWallet>;
|
|
39
|
-
/**
|
|
40
|
-
* Generates a new wallet with a BIP39 mnemonic of the given length.
|
|
41
|
-
*
|
|
42
|
-
* @param length The number of words in the mnemonic (12, 15, 18, 21 or 24).
|
|
43
|
-
* @param options An optional `Secp256k1HdWalletOptions` object optionally containing a bip39Password, hdPaths, and prefix.
|
|
44
|
-
*/
|
|
45
|
-
static generate(length?: 12 | 15 | 18 | 21 | 24, options?: Partial<Secp256k1HdWalletOptions>): Promise<Secp256k1HdWallet>;
|
|
46
|
-
/**
|
|
47
|
-
* Restores a wallet from an encrypted serialization.
|
|
48
|
-
*
|
|
49
|
-
* @param password The user provided password used to generate an encryption key via a KDF.
|
|
50
|
-
* This is not normalized internally (see "Unicode normalization" to learn more).
|
|
51
|
-
*/
|
|
52
|
-
static deserialize(serialization: string, password: string): Promise<Secp256k1HdWallet>;
|
|
53
|
-
/**
|
|
54
|
-
* Restores a wallet from an encrypted serialization.
|
|
55
|
-
*
|
|
56
|
-
* This is an advanced alternative to calling `deserialize(serialization, password)` directly, which allows
|
|
57
|
-
* you to offload the KDF execution to a non-UI thread (e.g. in a WebWorker).
|
|
58
|
-
*
|
|
59
|
-
* The caller is responsible for ensuring the key was derived with the given KDF configuration. This can be
|
|
60
|
-
* done using `extractKdfConfiguration(serialization)` and `executeKdf(password, kdfConfiguration)` from this package.
|
|
61
|
-
*/
|
|
62
|
-
static deserializeWithEncryptionKey(serialization: string, encryptionKey: Uint8Array): Promise<Secp256k1HdWallet>;
|
|
63
|
-
private static deserializeTypeV1;
|
|
64
|
-
/** Base secret */
|
|
65
|
-
private readonly secret;
|
|
66
|
-
/** BIP39 seed */
|
|
67
|
-
private readonly seed;
|
|
68
|
-
/** Derivation instruction */
|
|
69
|
-
private readonly accounts;
|
|
70
|
-
protected constructor(mnemonic: EnglishMnemonic, options: Secp256k1HdWalletConstructorOptions);
|
|
71
|
-
get mnemonic(): string;
|
|
72
|
-
getAccounts(): Promise<readonly AccountData[]>;
|
|
73
|
-
signAmino(signerAddress: string, signDoc: StdSignDoc): Promise<AminoSignResponse>;
|
|
74
|
-
/**
|
|
75
|
-
* Generates an encrypted serialization of this wallet.
|
|
76
|
-
*
|
|
77
|
-
* @param password The user provided password used to generate an encryption key via a KDF.
|
|
78
|
-
* This is not normalized internally (see "Unicode normalization" to learn more).
|
|
79
|
-
*/
|
|
80
|
-
serialize(password: string): Promise<string>;
|
|
81
|
-
/**
|
|
82
|
-
* Generates an encrypted serialization of this wallet.
|
|
83
|
-
*
|
|
84
|
-
* This is an advanced alternative to calling `serialize(password)` directly, which allows you to
|
|
85
|
-
* offload the KDF execution to a non-UI thread (e.g. in a WebWorker).
|
|
86
|
-
*
|
|
87
|
-
* The caller is responsible for ensuring the key was derived with the given KDF options. If this
|
|
88
|
-
* is not the case, the wallet cannot be restored with the original password.
|
|
89
|
-
*/
|
|
90
|
-
serializeWithEncryptionKey(encryptionKey: Uint8Array, kdfConfiguration: KdfConfiguration): Promise<string>;
|
|
91
|
-
private getKeyPair;
|
|
92
|
-
private getAccountsWithPrivkeys;
|
|
93
|
-
}
|
|
94
|
-
export {};
|
|
@@ -1,437 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __assign = (this && this.__assign) || function () {
|
|
3
|
-
__assign = Object.assign || function(t) {
|
|
4
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
-
s = arguments[i];
|
|
6
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
-
t[p] = s[p];
|
|
8
|
-
}
|
|
9
|
-
return t;
|
|
10
|
-
};
|
|
11
|
-
return __assign.apply(this, arguments);
|
|
12
|
-
};
|
|
13
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
14
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
15
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
16
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
17
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
18
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
19
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
20
|
-
});
|
|
21
|
-
};
|
|
22
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
23
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
24
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
25
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
26
|
-
function step(op) {
|
|
27
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
28
|
-
while (_) try {
|
|
29
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
30
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
31
|
-
switch (op[0]) {
|
|
32
|
-
case 0: case 1: t = op; break;
|
|
33
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
34
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
35
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
36
|
-
default:
|
|
37
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
38
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
39
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
40
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
41
|
-
if (t[2]) _.ops.pop();
|
|
42
|
-
_.trys.pop(); continue;
|
|
43
|
-
}
|
|
44
|
-
op = body.call(thisArg, _);
|
|
45
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
46
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
47
|
-
}
|
|
48
|
-
};
|
|
49
|
-
var __read = (this && this.__read) || function (o, n) {
|
|
50
|
-
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
51
|
-
if (!m) return o;
|
|
52
|
-
var i = m.call(o), r, ar = [], e;
|
|
53
|
-
try {
|
|
54
|
-
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
55
|
-
}
|
|
56
|
-
catch (error) { e = { error: error }; }
|
|
57
|
-
finally {
|
|
58
|
-
try {
|
|
59
|
-
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
60
|
-
}
|
|
61
|
-
finally { if (e) throw e.error; }
|
|
62
|
-
}
|
|
63
|
-
return ar;
|
|
64
|
-
};
|
|
65
|
-
var __spreadArray = (this && this.__spreadArray) || function (to, from) {
|
|
66
|
-
for (var i = 0, il = from.length, j = to.length; i < il; i++, j++)
|
|
67
|
-
to[j] = from[i];
|
|
68
|
-
return to;
|
|
69
|
-
};
|
|
70
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
71
|
-
exports.Secp256k1HdWallet = exports.extractKdfConfiguration = void 0;
|
|
72
|
-
var crypto_1 = require("@cosmjs/crypto");
|
|
73
|
-
var encoding_1 = require("@cosmjs/encoding");
|
|
74
|
-
var utils_1 = require("@cosmjs/utils");
|
|
75
|
-
var addresses_1 = require("./addresses");
|
|
76
|
-
var paths_1 = require("./paths");
|
|
77
|
-
var signature_1 = require("./signature");
|
|
78
|
-
var signdoc_1 = require("./signdoc");
|
|
79
|
-
var wallet_1 = require("./wallet");
|
|
80
|
-
var serializationTypeV1 = "secp256k1wallet-v1";
|
|
81
|
-
/**
|
|
82
|
-
* A KDF configuration that is not very strong but can be used on the main thread.
|
|
83
|
-
* It takes about 1 second in Node.js 16.0.0 and should have similar runtimes in other modern Wasm hosts.
|
|
84
|
-
*/
|
|
85
|
-
var basicPasswordHashingOptions = {
|
|
86
|
-
algorithm: "argon2id",
|
|
87
|
-
params: {
|
|
88
|
-
outputLength: 32,
|
|
89
|
-
opsLimit: 24,
|
|
90
|
-
memLimitKib: 12 * 1024,
|
|
91
|
-
},
|
|
92
|
-
};
|
|
93
|
-
function isDerivationJson(thing) {
|
|
94
|
-
if (!utils_1.isNonNullObject(thing))
|
|
95
|
-
return false;
|
|
96
|
-
if (typeof thing.hdPath !== "string")
|
|
97
|
-
return false;
|
|
98
|
-
if (typeof thing.prefix !== "string")
|
|
99
|
-
return false;
|
|
100
|
-
return true;
|
|
101
|
-
}
|
|
102
|
-
function extractKdfConfigurationV1(doc) {
|
|
103
|
-
return doc.kdf;
|
|
104
|
-
}
|
|
105
|
-
function extractKdfConfiguration(serialization) {
|
|
106
|
-
var root = JSON.parse(serialization);
|
|
107
|
-
if (!utils_1.isNonNullObject(root))
|
|
108
|
-
throw new Error("Root document is not an object.");
|
|
109
|
-
switch (root.type) {
|
|
110
|
-
case serializationTypeV1:
|
|
111
|
-
return extractKdfConfigurationV1(root);
|
|
112
|
-
default:
|
|
113
|
-
throw new Error("Unsupported serialization type");
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
exports.extractKdfConfiguration = extractKdfConfiguration;
|
|
117
|
-
var defaultOptions = {
|
|
118
|
-
bip39Password: "",
|
|
119
|
-
hdPaths: [paths_1.makeCosmoshubPath(0)],
|
|
120
|
-
prefix: "cosmos",
|
|
121
|
-
};
|
|
122
|
-
var Secp256k1HdWallet = /** @class */ (function () {
|
|
123
|
-
function Secp256k1HdWallet(mnemonic, options) {
|
|
124
|
-
var _a, _b;
|
|
125
|
-
var hdPaths = (_a = options.hdPaths) !== null && _a !== void 0 ? _a : defaultOptions.hdPaths;
|
|
126
|
-
var prefix = (_b = options.prefix) !== null && _b !== void 0 ? _b : defaultOptions.prefix;
|
|
127
|
-
this.secret = mnemonic;
|
|
128
|
-
this.seed = options.seed;
|
|
129
|
-
this.accounts = hdPaths.map(function (hdPath) { return ({
|
|
130
|
-
hdPath: hdPath,
|
|
131
|
-
prefix: prefix,
|
|
132
|
-
}); });
|
|
133
|
-
}
|
|
134
|
-
/**
|
|
135
|
-
* Restores a wallet from the given BIP39 mnemonic.
|
|
136
|
-
*
|
|
137
|
-
* @param mnemonic Any valid English mnemonic.
|
|
138
|
-
* @param options An optional `Secp256k1HdWalletOptions` object optionally containing a bip39Password, hdPaths, and prefix.
|
|
139
|
-
*/
|
|
140
|
-
Secp256k1HdWallet.fromMnemonic = function (mnemonic, options) {
|
|
141
|
-
if (options === void 0) { options = {}; }
|
|
142
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
143
|
-
var mnemonicChecked, seed;
|
|
144
|
-
return __generator(this, function (_a) {
|
|
145
|
-
switch (_a.label) {
|
|
146
|
-
case 0:
|
|
147
|
-
mnemonicChecked = new crypto_1.EnglishMnemonic(mnemonic);
|
|
148
|
-
return [4 /*yield*/, crypto_1.Bip39.mnemonicToSeed(mnemonicChecked, options.bip39Password)];
|
|
149
|
-
case 1:
|
|
150
|
-
seed = _a.sent();
|
|
151
|
-
return [2 /*return*/, new Secp256k1HdWallet(mnemonicChecked, __assign(__assign({}, options), { seed: seed }))];
|
|
152
|
-
}
|
|
153
|
-
});
|
|
154
|
-
});
|
|
155
|
-
};
|
|
156
|
-
/**
|
|
157
|
-
* Generates a new wallet with a BIP39 mnemonic of the given length.
|
|
158
|
-
*
|
|
159
|
-
* @param length The number of words in the mnemonic (12, 15, 18, 21 or 24).
|
|
160
|
-
* @param options An optional `Secp256k1HdWalletOptions` object optionally containing a bip39Password, hdPaths, and prefix.
|
|
161
|
-
*/
|
|
162
|
-
Secp256k1HdWallet.generate = function (length, options) {
|
|
163
|
-
if (length === void 0) { length = 12; }
|
|
164
|
-
if (options === void 0) { options = {}; }
|
|
165
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
166
|
-
var entropyLength, entropy, mnemonic;
|
|
167
|
-
return __generator(this, function (_a) {
|
|
168
|
-
entropyLength = 4 * Math.floor((11 * length) / 33);
|
|
169
|
-
entropy = crypto_1.Random.getBytes(entropyLength);
|
|
170
|
-
mnemonic = crypto_1.Bip39.encode(entropy);
|
|
171
|
-
return [2 /*return*/, Secp256k1HdWallet.fromMnemonic(mnemonic.toString(), options)];
|
|
172
|
-
});
|
|
173
|
-
});
|
|
174
|
-
};
|
|
175
|
-
/**
|
|
176
|
-
* Restores a wallet from an encrypted serialization.
|
|
177
|
-
*
|
|
178
|
-
* @param password The user provided password used to generate an encryption key via a KDF.
|
|
179
|
-
* This is not normalized internally (see "Unicode normalization" to learn more).
|
|
180
|
-
*/
|
|
181
|
-
Secp256k1HdWallet.deserialize = function (serialization, password) {
|
|
182
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
183
|
-
var root;
|
|
184
|
-
return __generator(this, function (_a) {
|
|
185
|
-
root = JSON.parse(serialization);
|
|
186
|
-
if (!utils_1.isNonNullObject(root))
|
|
187
|
-
throw new Error("Root document is not an object.");
|
|
188
|
-
switch (root.type) {
|
|
189
|
-
case serializationTypeV1:
|
|
190
|
-
return [2 /*return*/, Secp256k1HdWallet.deserializeTypeV1(serialization, password)];
|
|
191
|
-
default:
|
|
192
|
-
throw new Error("Unsupported serialization type");
|
|
193
|
-
}
|
|
194
|
-
return [2 /*return*/];
|
|
195
|
-
});
|
|
196
|
-
});
|
|
197
|
-
};
|
|
198
|
-
/**
|
|
199
|
-
* Restores a wallet from an encrypted serialization.
|
|
200
|
-
*
|
|
201
|
-
* This is an advanced alternative to calling `deserialize(serialization, password)` directly, which allows
|
|
202
|
-
* you to offload the KDF execution to a non-UI thread (e.g. in a WebWorker).
|
|
203
|
-
*
|
|
204
|
-
* The caller is responsible for ensuring the key was derived with the given KDF configuration. This can be
|
|
205
|
-
* done using `extractKdfConfiguration(serialization)` and `executeKdf(password, kdfConfiguration)` from this package.
|
|
206
|
-
*/
|
|
207
|
-
Secp256k1HdWallet.deserializeWithEncryptionKey = function (serialization, encryptionKey) {
|
|
208
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
209
|
-
var root, untypedRoot, _a, decryptedBytes, decryptedDocument, mnemonic, accounts, firstPrefix_1, hdPaths;
|
|
210
|
-
return __generator(this, function (_b) {
|
|
211
|
-
switch (_b.label) {
|
|
212
|
-
case 0:
|
|
213
|
-
root = JSON.parse(serialization);
|
|
214
|
-
if (!utils_1.isNonNullObject(root))
|
|
215
|
-
throw new Error("Root document is not an object.");
|
|
216
|
-
untypedRoot = root;
|
|
217
|
-
_a = untypedRoot.type;
|
|
218
|
-
switch (_a) {
|
|
219
|
-
case serializationTypeV1: return [3 /*break*/, 1];
|
|
220
|
-
}
|
|
221
|
-
return [3 /*break*/, 3];
|
|
222
|
-
case 1: return [4 /*yield*/, wallet_1.decrypt(encoding_1.fromBase64(untypedRoot.data), encryptionKey, untypedRoot.encryption)];
|
|
223
|
-
case 2:
|
|
224
|
-
decryptedBytes = _b.sent();
|
|
225
|
-
decryptedDocument = JSON.parse(encoding_1.fromUtf8(decryptedBytes));
|
|
226
|
-
mnemonic = decryptedDocument.mnemonic, accounts = decryptedDocument.accounts;
|
|
227
|
-
utils_1.assert(typeof mnemonic === "string");
|
|
228
|
-
if (!Array.isArray(accounts))
|
|
229
|
-
throw new Error("Property 'accounts' is not an array");
|
|
230
|
-
if (!accounts.every(function (account) { return isDerivationJson(account); })) {
|
|
231
|
-
throw new Error("Account is not in the correct format.");
|
|
232
|
-
}
|
|
233
|
-
firstPrefix_1 = accounts[0].prefix;
|
|
234
|
-
if (!accounts.every(function (_a) {
|
|
235
|
-
var prefix = _a.prefix;
|
|
236
|
-
return prefix === firstPrefix_1;
|
|
237
|
-
})) {
|
|
238
|
-
throw new Error("Accounts do not all have the same prefix");
|
|
239
|
-
}
|
|
240
|
-
hdPaths = accounts.map(function (_a) {
|
|
241
|
-
var hdPath = _a.hdPath;
|
|
242
|
-
return crypto_1.stringToPath(hdPath);
|
|
243
|
-
});
|
|
244
|
-
return [2 /*return*/, Secp256k1HdWallet.fromMnemonic(mnemonic, {
|
|
245
|
-
hdPaths: hdPaths,
|
|
246
|
-
prefix: firstPrefix_1,
|
|
247
|
-
})];
|
|
248
|
-
case 3: throw new Error("Unsupported serialization type");
|
|
249
|
-
}
|
|
250
|
-
});
|
|
251
|
-
});
|
|
252
|
-
};
|
|
253
|
-
Secp256k1HdWallet.deserializeTypeV1 = function (serialization, password) {
|
|
254
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
255
|
-
var root, encryptionKey;
|
|
256
|
-
return __generator(this, function (_a) {
|
|
257
|
-
switch (_a.label) {
|
|
258
|
-
case 0:
|
|
259
|
-
root = JSON.parse(serialization);
|
|
260
|
-
if (!utils_1.isNonNullObject(root))
|
|
261
|
-
throw new Error("Root document is not an object.");
|
|
262
|
-
return [4 /*yield*/, wallet_1.executeKdf(password, root.kdf)];
|
|
263
|
-
case 1:
|
|
264
|
-
encryptionKey = _a.sent();
|
|
265
|
-
return [2 /*return*/, Secp256k1HdWallet.deserializeWithEncryptionKey(serialization, encryptionKey)];
|
|
266
|
-
}
|
|
267
|
-
});
|
|
268
|
-
});
|
|
269
|
-
};
|
|
270
|
-
Object.defineProperty(Secp256k1HdWallet.prototype, "mnemonic", {
|
|
271
|
-
get: function () {
|
|
272
|
-
return this.secret.toString();
|
|
273
|
-
},
|
|
274
|
-
enumerable: false,
|
|
275
|
-
configurable: true
|
|
276
|
-
});
|
|
277
|
-
Secp256k1HdWallet.prototype.getAccounts = function () {
|
|
278
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
279
|
-
var accountsWithPrivkeys;
|
|
280
|
-
return __generator(this, function (_a) {
|
|
281
|
-
switch (_a.label) {
|
|
282
|
-
case 0: return [4 /*yield*/, this.getAccountsWithPrivkeys()];
|
|
283
|
-
case 1:
|
|
284
|
-
accountsWithPrivkeys = _a.sent();
|
|
285
|
-
return [2 /*return*/, accountsWithPrivkeys.map(function (_a) {
|
|
286
|
-
var algo = _a.algo, pubkey = _a.pubkey, address = _a.address;
|
|
287
|
-
return ({
|
|
288
|
-
algo: algo,
|
|
289
|
-
pubkey: pubkey,
|
|
290
|
-
address: address,
|
|
291
|
-
});
|
|
292
|
-
})];
|
|
293
|
-
}
|
|
294
|
-
});
|
|
295
|
-
});
|
|
296
|
-
};
|
|
297
|
-
Secp256k1HdWallet.prototype.signAmino = function (signerAddress, signDoc) {
|
|
298
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
299
|
-
var accounts, account, privkey, pubkey, message, signature, signatureBytes;
|
|
300
|
-
return __generator(this, function (_a) {
|
|
301
|
-
switch (_a.label) {
|
|
302
|
-
case 0: return [4 /*yield*/, this.getAccountsWithPrivkeys()];
|
|
303
|
-
case 1:
|
|
304
|
-
accounts = _a.sent();
|
|
305
|
-
account = accounts.find(function (_a) {
|
|
306
|
-
var address = _a.address;
|
|
307
|
-
return address === signerAddress;
|
|
308
|
-
});
|
|
309
|
-
if (account === undefined) {
|
|
310
|
-
throw new Error("Address " + signerAddress + " not found in wallet");
|
|
311
|
-
}
|
|
312
|
-
privkey = account.privkey, pubkey = account.pubkey;
|
|
313
|
-
message = crypto_1.sha256(signdoc_1.serializeSignDoc(signDoc));
|
|
314
|
-
return [4 /*yield*/, crypto_1.Secp256k1.createSignature(message, privkey)];
|
|
315
|
-
case 2:
|
|
316
|
-
signature = _a.sent();
|
|
317
|
-
signatureBytes = new Uint8Array(__spreadArray(__spreadArray([], __read(signature.r(32))), __read(signature.s(32))));
|
|
318
|
-
return [2 /*return*/, {
|
|
319
|
-
signed: signDoc,
|
|
320
|
-
signature: signature_1.encodeSecp256k1Signature(pubkey, signatureBytes),
|
|
321
|
-
}];
|
|
322
|
-
}
|
|
323
|
-
});
|
|
324
|
-
});
|
|
325
|
-
};
|
|
326
|
-
/**
|
|
327
|
-
* Generates an encrypted serialization of this wallet.
|
|
328
|
-
*
|
|
329
|
-
* @param password The user provided password used to generate an encryption key via a KDF.
|
|
330
|
-
* This is not normalized internally (see "Unicode normalization" to learn more).
|
|
331
|
-
*/
|
|
332
|
-
Secp256k1HdWallet.prototype.serialize = function (password) {
|
|
333
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
334
|
-
var kdfConfiguration, encryptionKey;
|
|
335
|
-
return __generator(this, function (_a) {
|
|
336
|
-
switch (_a.label) {
|
|
337
|
-
case 0:
|
|
338
|
-
kdfConfiguration = basicPasswordHashingOptions;
|
|
339
|
-
return [4 /*yield*/, wallet_1.executeKdf(password, kdfConfiguration)];
|
|
340
|
-
case 1:
|
|
341
|
-
encryptionKey = _a.sent();
|
|
342
|
-
return [2 /*return*/, this.serializeWithEncryptionKey(encryptionKey, kdfConfiguration)];
|
|
343
|
-
}
|
|
344
|
-
});
|
|
345
|
-
});
|
|
346
|
-
};
|
|
347
|
-
/**
|
|
348
|
-
* Generates an encrypted serialization of this wallet.
|
|
349
|
-
*
|
|
350
|
-
* This is an advanced alternative to calling `serialize(password)` directly, which allows you to
|
|
351
|
-
* offload the KDF execution to a non-UI thread (e.g. in a WebWorker).
|
|
352
|
-
*
|
|
353
|
-
* The caller is responsible for ensuring the key was derived with the given KDF options. If this
|
|
354
|
-
* is not the case, the wallet cannot be restored with the original password.
|
|
355
|
-
*/
|
|
356
|
-
Secp256k1HdWallet.prototype.serializeWithEncryptionKey = function (encryptionKey, kdfConfiguration) {
|
|
357
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
358
|
-
var dataToEncrypt, dataToEncryptRaw, encryptionConfiguration, encryptedData, out;
|
|
359
|
-
return __generator(this, function (_a) {
|
|
360
|
-
switch (_a.label) {
|
|
361
|
-
case 0:
|
|
362
|
-
dataToEncrypt = {
|
|
363
|
-
mnemonic: this.mnemonic,
|
|
364
|
-
accounts: this.accounts.map(function (_a) {
|
|
365
|
-
var hdPath = _a.hdPath, prefix = _a.prefix;
|
|
366
|
-
return ({
|
|
367
|
-
hdPath: crypto_1.pathToString(hdPath),
|
|
368
|
-
prefix: prefix,
|
|
369
|
-
});
|
|
370
|
-
}),
|
|
371
|
-
};
|
|
372
|
-
dataToEncryptRaw = encoding_1.toUtf8(JSON.stringify(dataToEncrypt));
|
|
373
|
-
encryptionConfiguration = {
|
|
374
|
-
algorithm: wallet_1.supportedAlgorithms.xchacha20poly1305Ietf,
|
|
375
|
-
};
|
|
376
|
-
return [4 /*yield*/, wallet_1.encrypt(dataToEncryptRaw, encryptionKey, encryptionConfiguration)];
|
|
377
|
-
case 1:
|
|
378
|
-
encryptedData = _a.sent();
|
|
379
|
-
out = {
|
|
380
|
-
type: serializationTypeV1,
|
|
381
|
-
kdf: kdfConfiguration,
|
|
382
|
-
encryption: encryptionConfiguration,
|
|
383
|
-
data: encoding_1.toBase64(encryptedData),
|
|
384
|
-
};
|
|
385
|
-
return [2 /*return*/, JSON.stringify(out)];
|
|
386
|
-
}
|
|
387
|
-
});
|
|
388
|
-
});
|
|
389
|
-
};
|
|
390
|
-
Secp256k1HdWallet.prototype.getKeyPair = function (hdPath) {
|
|
391
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
392
|
-
var privkey, pubkey;
|
|
393
|
-
return __generator(this, function (_a) {
|
|
394
|
-
switch (_a.label) {
|
|
395
|
-
case 0:
|
|
396
|
-
privkey = crypto_1.Slip10.derivePath(crypto_1.Slip10Curve.Secp256k1, this.seed, hdPath).privkey;
|
|
397
|
-
return [4 /*yield*/, crypto_1.Secp256k1.makeKeypair(privkey)];
|
|
398
|
-
case 1:
|
|
399
|
-
pubkey = (_a.sent()).pubkey;
|
|
400
|
-
return [2 /*return*/, {
|
|
401
|
-
privkey: privkey,
|
|
402
|
-
pubkey: crypto_1.Secp256k1.compressPubkey(pubkey),
|
|
403
|
-
}];
|
|
404
|
-
}
|
|
405
|
-
});
|
|
406
|
-
});
|
|
407
|
-
};
|
|
408
|
-
Secp256k1HdWallet.prototype.getAccountsWithPrivkeys = function () {
|
|
409
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
410
|
-
var _this = this;
|
|
411
|
-
return __generator(this, function (_a) {
|
|
412
|
-
return [2 /*return*/, Promise.all(this.accounts.map(function (_a) {
|
|
413
|
-
var hdPath = _a.hdPath, prefix = _a.prefix;
|
|
414
|
-
return __awaiter(_this, void 0, void 0, function () {
|
|
415
|
-
var _b, privkey, pubkey, address;
|
|
416
|
-
return __generator(this, function (_c) {
|
|
417
|
-
switch (_c.label) {
|
|
418
|
-
case 0: return [4 /*yield*/, this.getKeyPair(hdPath)];
|
|
419
|
-
case 1:
|
|
420
|
-
_b = _c.sent(), privkey = _b.privkey, pubkey = _b.pubkey;
|
|
421
|
-
address = encoding_1.Bech32.encode(prefix, addresses_1.rawSecp256k1PubkeyToRawAddress(pubkey));
|
|
422
|
-
return [2 /*return*/, {
|
|
423
|
-
algo: "secp256k1",
|
|
424
|
-
privkey: privkey,
|
|
425
|
-
pubkey: pubkey,
|
|
426
|
-
address: address,
|
|
427
|
-
}];
|
|
428
|
-
}
|
|
429
|
-
});
|
|
430
|
-
});
|
|
431
|
-
}))];
|
|
432
|
-
});
|
|
433
|
-
});
|
|
434
|
-
};
|
|
435
|
-
return Secp256k1HdWallet;
|
|
436
|
-
}());
|
|
437
|
-
exports.Secp256k1HdWallet = Secp256k1HdWallet;
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { StdSignDoc } from "./signdoc";
|
|
2
|
-
import { AccountData, AminoSignResponse, OfflineAminoSigner } from "./signer";
|
|
3
|
-
/**
|
|
4
|
-
* A wallet that holds a single secp256k1 keypair.
|
|
5
|
-
*
|
|
6
|
-
* If you want to work with BIP39 mnemonics and multiple accounts, use Secp256k1HdWallet.
|
|
7
|
-
*/
|
|
8
|
-
export declare class Secp256k1Wallet implements OfflineAminoSigner {
|
|
9
|
-
/**
|
|
10
|
-
* Creates a Secp256k1Wallet from the given private key
|
|
11
|
-
*
|
|
12
|
-
* @param privkey The private key.
|
|
13
|
-
* @param prefix The bech32 address prefix (human readable part). Defaults to "cosmos".
|
|
14
|
-
*/
|
|
15
|
-
static fromKey(privkey: Uint8Array, prefix?: string): Promise<Secp256k1Wallet>;
|
|
16
|
-
private readonly pubkey;
|
|
17
|
-
private readonly privkey;
|
|
18
|
-
private readonly prefix;
|
|
19
|
-
private constructor();
|
|
20
|
-
private get address();
|
|
21
|
-
getAccounts(): Promise<readonly AccountData[]>;
|
|
22
|
-
signAmino(signerAddress: string, signDoc: StdSignDoc): Promise<AminoSignResponse>;
|
|
23
|
-
}
|