@firmachain/firma-js 0.2.16 → 0.2.20
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/FirmaBankService.js +3 -3
- package/dist/sdk/FirmaContractService.js +8 -8
- package/dist/sdk/FirmaDistributionService.js +10 -10
- package/dist/sdk/FirmaFeeGrantService.js +6 -6
- package/dist/sdk/FirmaGovService.js +15 -15
- package/dist/sdk/FirmaNftService.js +6 -6
- package/dist/sdk/FirmaStakingService.js +10 -10
- package/dist/sdk/FirmaTokenService.js +8 -8
- package/dist/sdk/FirmaUtil.d.ts +4 -0
- package/dist/sdk/FirmaUtil.js +65 -6
- package/dist/sdk/FirmaWalletService.d.ts +9 -1
- package/dist/sdk/FirmaWalletService.js +39 -5
- package/dist/sdk/firmachain/amino/addresses.d.ts +5 -0
- package/dist/sdk/firmachain/amino/addresses.js +46 -0
- package/dist/sdk/firmachain/amino/aminomsgs.d.ts +281 -0
- package/dist/sdk/firmachain/amino/aminomsgs.js +77 -0
- package/dist/sdk/firmachain/amino/aminotypes.d.ts +22 -0
- package/dist/sdk/firmachain/amino/aminotypes.js +521 -0
- package/dist/sdk/firmachain/amino/coins.d.ts +30 -0
- package/dist/sdk/firmachain/amino/coins.js +69 -0
- package/dist/sdk/firmachain/amino/encoding.d.ts +24 -0
- package/dist/sdk/firmachain/amino/encoding.js +234 -0
- package/dist/sdk/firmachain/amino/multisig.d.ts +10 -0
- package/dist/sdk/firmachain/amino/multisig.js +42 -0
- package/dist/sdk/firmachain/amino/paths.d.ts +6 -0
- package/dist/sdk/firmachain/amino/paths.js +18 -0
- package/dist/sdk/firmachain/amino/pubkeys.d.ts +47 -0
- package/dist/sdk/firmachain/amino/pubkeys.js +29 -0
- package/dist/sdk/firmachain/amino/secp256k1hdwallet.d.ts +94 -0
- package/dist/sdk/firmachain/amino/secp256k1hdwallet.js +437 -0
- package/dist/sdk/firmachain/amino/secp256k1wallet.d.ts +23 -0
- package/dist/sdk/firmachain/amino/secp256k1wallet.js +141 -0
- package/dist/sdk/firmachain/amino/signature.d.ts +16 -0
- package/dist/sdk/firmachain/amino/signature.js +36 -0
- package/dist/sdk/firmachain/amino/signdoc.d.ts +26 -0
- package/dist/sdk/firmachain/amino/signdoc.js +42 -0
- package/dist/sdk/firmachain/amino/signer.d.ts +33 -0
- package/dist/sdk/firmachain/amino/signer.js +2 -0
- package/dist/sdk/firmachain/amino/stdtx.d.ts +15 -0
- package/dist/sdk/firmachain/amino/stdtx.js +17 -0
- package/dist/sdk/firmachain/amino/wallet.d.ts +32 -0
- package/dist/sdk/firmachain/amino/wallet.js +132 -0
- package/dist/sdk/firmachain/bank/BankTxClient.d.ts +3 -2
- package/dist/sdk/firmachain/common/ITxClient.d.ts +4 -2
- package/dist/sdk/firmachain/common/ITxClient.js +10 -6
- package/dist/sdk/firmachain/common/LedgerSigningStargateClient.d.ts +27 -0
- package/dist/sdk/firmachain/common/LedgerSigningStargateClient.js +165 -0
- package/dist/sdk/firmachain/common/LedgerWallet.d.ts +14 -0
- package/dist/sdk/firmachain/common/LedgerWallet.js +147 -0
- package/dist/sdk/firmachain/common/signing.js +17 -1
- package/dist/sdk/firmachain/common/signingstargateclient.js +19 -3
- package/dist/sdk/firmachain/common/stargateclient.js +5 -2
- package/dist/sdk/firmachain/contract/ContractTxClient.d.ts +3 -2
- package/dist/sdk/firmachain/contract/ContractTxTypes.js +50 -9
- package/dist/sdk/firmachain/distribution/DistributionTxClient.d.ts +3 -2
- package/dist/sdk/firmachain/distribution/index.js +0 -1
- package/dist/sdk/firmachain/feegrant/FeeGrantTxClient.d.ts +3 -2
- package/dist/sdk/firmachain/feegrant/FeeGrantTxTypes.js +63 -13
- package/dist/sdk/firmachain/google/protobuf/any.js +3 -2
- package/dist/sdk/firmachain/google/protobuf/descriptor.js +1364 -324
- package/dist/sdk/firmachain/gov/GovTxClient.d.ts +3 -2
- package/dist/sdk/firmachain/gov/index.js +0 -1
- package/dist/sdk/firmachain/nft/NftTxClient.d.ts +3 -2
- package/dist/sdk/firmachain/staking/StakingTxClient.d.ts +3 -2
- package/dist/sdk/firmachain/token/TokenTxClient.d.ts +3 -2
- package/package.json +1 -1
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { Coin } from "./coins";
|
|
2
|
+
export interface AminoMsg {
|
|
3
|
+
readonly type: string;
|
|
4
|
+
readonly value: any;
|
|
5
|
+
}
|
|
6
|
+
export interface StdFee {
|
|
7
|
+
amount: Coin[];
|
|
8
|
+
gas: string;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* The document to be signed
|
|
12
|
+
*
|
|
13
|
+
* @see https://docs.cosmos.network/master/modules/auth/03_types.html#stdsigndoc
|
|
14
|
+
*/
|
|
15
|
+
export interface StdSignDoc {
|
|
16
|
+
readonly chain_id: string;
|
|
17
|
+
readonly account_number: string;
|
|
18
|
+
readonly sequence: string;
|
|
19
|
+
readonly fee: StdFee;
|
|
20
|
+
readonly msgs: readonly AminoMsg[];
|
|
21
|
+
readonly memo: string;
|
|
22
|
+
}
|
|
23
|
+
/** Returns a JSON string with objects sorted by key */
|
|
24
|
+
export declare function sortedJsonStringify(obj: any): string;
|
|
25
|
+
export declare function makeSignDoc(msgs: readonly AminoMsg[], fee: StdFee, chainId: string, memo: string | undefined, accountNumber: number | string, sequence: number | string): StdSignDoc;
|
|
26
|
+
export declare function serializeSignDoc(signDoc: StdSignDoc): Uint8Array;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.serializeSignDoc = exports.makeSignDoc = exports.sortedJsonStringify = void 0;
|
|
4
|
+
/* eslint-disable @typescript-eslint/naming-convention */
|
|
5
|
+
var encoding_1 = require("@cosmjs/encoding");
|
|
6
|
+
var math_1 = require("@cosmjs/math");
|
|
7
|
+
function sortedObject(obj) {
|
|
8
|
+
if (typeof obj !== "object" || obj === null) {
|
|
9
|
+
return obj;
|
|
10
|
+
}
|
|
11
|
+
if (Array.isArray(obj)) {
|
|
12
|
+
return obj.map(sortedObject);
|
|
13
|
+
}
|
|
14
|
+
var sortedKeys = Object.keys(obj).sort();
|
|
15
|
+
var result = {};
|
|
16
|
+
// NOTE: Use forEach instead of reduce for performance with large objects eg Wasm code
|
|
17
|
+
sortedKeys.forEach(function (key) {
|
|
18
|
+
result[key] = sortedObject(obj[key]);
|
|
19
|
+
});
|
|
20
|
+
return result;
|
|
21
|
+
}
|
|
22
|
+
/** Returns a JSON string with objects sorted by key */
|
|
23
|
+
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
|
|
24
|
+
function sortedJsonStringify(obj) {
|
|
25
|
+
return JSON.stringify(sortedObject(obj));
|
|
26
|
+
}
|
|
27
|
+
exports.sortedJsonStringify = sortedJsonStringify;
|
|
28
|
+
function makeSignDoc(msgs, fee, chainId, memo, accountNumber, sequence) {
|
|
29
|
+
return {
|
|
30
|
+
chain_id: chainId,
|
|
31
|
+
account_number: math_1.Uint53.fromString(accountNumber.toString()).toString(),
|
|
32
|
+
sequence: math_1.Uint53.fromString(sequence.toString()).toString(),
|
|
33
|
+
fee: fee,
|
|
34
|
+
msgs: msgs,
|
|
35
|
+
memo: memo || "",
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
exports.makeSignDoc = makeSignDoc;
|
|
39
|
+
function serializeSignDoc(signDoc) {
|
|
40
|
+
return encoding_1.toUtf8(sortedJsonStringify(signDoc));
|
|
41
|
+
}
|
|
42
|
+
exports.serializeSignDoc = serializeSignDoc;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { StdSignature } from "./signature";
|
|
2
|
+
import { StdSignDoc } from "./signdoc";
|
|
3
|
+
export declare type Algo = "secp256k1" | "ed25519" | "sr25519";
|
|
4
|
+
export interface AccountData {
|
|
5
|
+
/** A printable address (typically bech32 encoded) */
|
|
6
|
+
readonly address: string;
|
|
7
|
+
readonly algo: Algo;
|
|
8
|
+
readonly pubkey: Uint8Array;
|
|
9
|
+
}
|
|
10
|
+
export interface AminoSignResponse {
|
|
11
|
+
/**
|
|
12
|
+
* The sign doc that was signed.
|
|
13
|
+
* This may be different from the input signDoc when the signer modifies it as part of the signing process.
|
|
14
|
+
*/
|
|
15
|
+
readonly signed: StdSignDoc;
|
|
16
|
+
readonly signature: StdSignature;
|
|
17
|
+
}
|
|
18
|
+
export interface OfflineAminoSigner {
|
|
19
|
+
/**
|
|
20
|
+
* Get AccountData array from wallet. Rejects if not enabled.
|
|
21
|
+
*/
|
|
22
|
+
readonly getAccounts: () => Promise<readonly AccountData[]>;
|
|
23
|
+
/**
|
|
24
|
+
* Request signature from whichever key corresponds to provided bech32-encoded address. Rejects if not enabled.
|
|
25
|
+
*
|
|
26
|
+
* The signer implementation may offer the user the ability to override parts of the signDoc. It must
|
|
27
|
+
* return the doc that was signed in the response.
|
|
28
|
+
*
|
|
29
|
+
* @param signerAddress The address of the account that should sign the transaction
|
|
30
|
+
* @param signDoc The content that should be signed
|
|
31
|
+
*/
|
|
32
|
+
readonly signAmino: (signerAddress: string, signDoc: StdSignDoc) => Promise<AminoSignResponse>;
|
|
33
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { StdSignature } from "./signature";
|
|
2
|
+
import { AminoMsg, StdFee, StdSignDoc } from "./signdoc";
|
|
3
|
+
/**
|
|
4
|
+
* A Cosmos SDK StdTx
|
|
5
|
+
*
|
|
6
|
+
* @see https://docs.cosmos.network/master/modules/auth/03_types.html#stdtx
|
|
7
|
+
*/
|
|
8
|
+
export interface StdTx {
|
|
9
|
+
readonly msg: readonly AminoMsg[];
|
|
10
|
+
readonly fee: StdFee;
|
|
11
|
+
readonly signatures: readonly StdSignature[];
|
|
12
|
+
readonly memo: string | undefined;
|
|
13
|
+
}
|
|
14
|
+
export declare function isStdTx(txValue: unknown): txValue is StdTx;
|
|
15
|
+
export declare function makeStdTx(content: Pick<StdSignDoc, "msgs" | "fee" | "memo">, signatures: StdSignature | readonly StdSignature[]): StdTx;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.makeStdTx = exports.isStdTx = void 0;
|
|
4
|
+
function isStdTx(txValue) {
|
|
5
|
+
var _a = txValue, memo = _a.memo, msg = _a.msg, fee = _a.fee, signatures = _a.signatures;
|
|
6
|
+
return (typeof memo === "string" && Array.isArray(msg) && typeof fee === "object" && Array.isArray(signatures));
|
|
7
|
+
}
|
|
8
|
+
exports.isStdTx = isStdTx;
|
|
9
|
+
function makeStdTx(content, signatures) {
|
|
10
|
+
return {
|
|
11
|
+
msg: content.msgs,
|
|
12
|
+
fee: content.fee,
|
|
13
|
+
memo: content.memo,
|
|
14
|
+
signatures: Array.isArray(signatures) ? signatures : [signatures],
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
exports.makeStdTx = makeStdTx;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A fixed salt is chosen to archive a deterministic password to key derivation.
|
|
3
|
+
* This reduces the scope of a potential rainbow attack to all CosmJS users.
|
|
4
|
+
* Must be 16 bytes due to implementation limitations.
|
|
5
|
+
*/
|
|
6
|
+
export declare const cosmjsSalt: Uint8Array;
|
|
7
|
+
export interface KdfConfiguration {
|
|
8
|
+
/**
|
|
9
|
+
* An algorithm identifier, such as "argon2id" or "scrypt".
|
|
10
|
+
*/
|
|
11
|
+
readonly algorithm: string;
|
|
12
|
+
/** A map of algorithm-specific parameters */
|
|
13
|
+
readonly params: Record<string, unknown>;
|
|
14
|
+
}
|
|
15
|
+
export declare function executeKdf(password: string, configuration: KdfConfiguration): Promise<Uint8Array>;
|
|
16
|
+
/**
|
|
17
|
+
* Configuration how to encrypt data or how data was encrypted.
|
|
18
|
+
* This is stored as part of the wallet serialization and must only contain JSON types.
|
|
19
|
+
*/
|
|
20
|
+
export interface EncryptionConfiguration {
|
|
21
|
+
/**
|
|
22
|
+
* An algorithm identifier, such as "xchacha20poly1305-ietf".
|
|
23
|
+
*/
|
|
24
|
+
readonly algorithm: string;
|
|
25
|
+
/** A map of algorithm-specific parameters */
|
|
26
|
+
readonly params?: Record<string, unknown>;
|
|
27
|
+
}
|
|
28
|
+
export declare const supportedAlgorithms: {
|
|
29
|
+
xchacha20poly1305Ietf: string;
|
|
30
|
+
};
|
|
31
|
+
export declare function encrypt(plaintext: Uint8Array, encryptionKey: Uint8Array, config: EncryptionConfiguration): Promise<Uint8Array>;
|
|
32
|
+
export declare function decrypt(ciphertext: Uint8Array, encryptionKey: Uint8Array, config: EncryptionConfiguration): Promise<Uint8Array>;
|
|
@@ -0,0 +1,132 @@
|
|
|
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
|
+
var __read = (this && this.__read) || function (o, n) {
|
|
39
|
+
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
40
|
+
if (!m) return o;
|
|
41
|
+
var i = m.call(o), r, ar = [], e;
|
|
42
|
+
try {
|
|
43
|
+
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
44
|
+
}
|
|
45
|
+
catch (error) { e = { error: error }; }
|
|
46
|
+
finally {
|
|
47
|
+
try {
|
|
48
|
+
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
49
|
+
}
|
|
50
|
+
finally { if (e) throw e.error; }
|
|
51
|
+
}
|
|
52
|
+
return ar;
|
|
53
|
+
};
|
|
54
|
+
var __spreadArray = (this && this.__spreadArray) || function (to, from) {
|
|
55
|
+
for (var i = 0, il = from.length, j = to.length; i < il; i++, j++)
|
|
56
|
+
to[j] = from[i];
|
|
57
|
+
return to;
|
|
58
|
+
};
|
|
59
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
60
|
+
exports.decrypt = exports.encrypt = exports.supportedAlgorithms = exports.executeKdf = exports.cosmjsSalt = void 0;
|
|
61
|
+
var crypto_1 = require("@cosmjs/crypto");
|
|
62
|
+
var encoding_1 = require("@cosmjs/encoding");
|
|
63
|
+
/**
|
|
64
|
+
* A fixed salt is chosen to archive a deterministic password to key derivation.
|
|
65
|
+
* This reduces the scope of a potential rainbow attack to all CosmJS users.
|
|
66
|
+
* Must be 16 bytes due to implementation limitations.
|
|
67
|
+
*/
|
|
68
|
+
exports.cosmjsSalt = encoding_1.toAscii("The CosmJS salt.");
|
|
69
|
+
function executeKdf(password, configuration) {
|
|
70
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
71
|
+
var options;
|
|
72
|
+
return __generator(this, function (_a) {
|
|
73
|
+
switch (configuration.algorithm) {
|
|
74
|
+
case "argon2id": {
|
|
75
|
+
options = configuration.params;
|
|
76
|
+
if (!crypto_1.isArgon2idOptions(options))
|
|
77
|
+
throw new Error("Invalid format of argon2id params");
|
|
78
|
+
return [2 /*return*/, crypto_1.Argon2id.execute(password, exports.cosmjsSalt, options)];
|
|
79
|
+
}
|
|
80
|
+
default:
|
|
81
|
+
throw new Error("Unsupported KDF algorithm");
|
|
82
|
+
}
|
|
83
|
+
return [2 /*return*/];
|
|
84
|
+
});
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
exports.executeKdf = executeKdf;
|
|
88
|
+
exports.supportedAlgorithms = {
|
|
89
|
+
xchacha20poly1305Ietf: "xchacha20poly1305-ietf",
|
|
90
|
+
};
|
|
91
|
+
function encrypt(plaintext, encryptionKey, config) {
|
|
92
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
93
|
+
var _a, nonce, _b, _c;
|
|
94
|
+
return __generator(this, function (_d) {
|
|
95
|
+
switch (_d.label) {
|
|
96
|
+
case 0:
|
|
97
|
+
_a = config.algorithm;
|
|
98
|
+
switch (_a) {
|
|
99
|
+
case exports.supportedAlgorithms.xchacha20poly1305Ietf: return [3 /*break*/, 1];
|
|
100
|
+
}
|
|
101
|
+
return [3 /*break*/, 3];
|
|
102
|
+
case 1:
|
|
103
|
+
nonce = crypto_1.Random.getBytes(crypto_1.xchacha20NonceLength);
|
|
104
|
+
_b = Uint8Array.bind;
|
|
105
|
+
_c = [__spreadArray([], __read(nonce))];
|
|
106
|
+
return [4 /*yield*/, crypto_1.Xchacha20poly1305Ietf.encrypt(plaintext, encryptionKey, nonce)];
|
|
107
|
+
case 2:
|
|
108
|
+
// Prepend fixed-length nonce to ciphertext as suggested in the example from https://github.com/jedisct1/libsodium.js#api
|
|
109
|
+
return [2 /*return*/, new (_b.apply(Uint8Array, [void 0, __spreadArray.apply(void 0, _c.concat([__read.apply(void 0, [(_d.sent())])]))]))()];
|
|
110
|
+
case 3: throw new Error("Unsupported encryption algorithm: '" + config.algorithm + "'");
|
|
111
|
+
}
|
|
112
|
+
});
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
exports.encrypt = encrypt;
|
|
116
|
+
function decrypt(ciphertext, encryptionKey, config) {
|
|
117
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
118
|
+
var nonce;
|
|
119
|
+
return __generator(this, function (_a) {
|
|
120
|
+
switch (config.algorithm) {
|
|
121
|
+
case exports.supportedAlgorithms.xchacha20poly1305Ietf: {
|
|
122
|
+
nonce = ciphertext.slice(0, crypto_1.xchacha20NonceLength);
|
|
123
|
+
return [2 /*return*/, crypto_1.Xchacha20poly1305Ietf.decrypt(ciphertext.slice(crypto_1.xchacha20NonceLength), encryptionKey, nonce)];
|
|
124
|
+
}
|
|
125
|
+
default:
|
|
126
|
+
throw new Error("Unsupported encryption algorithm: '" + config.algorithm + "'");
|
|
127
|
+
}
|
|
128
|
+
return [2 /*return*/];
|
|
129
|
+
});
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
exports.decrypt = decrypt;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { EncodeObject
|
|
1
|
+
import { EncodeObject } from "@cosmjs/proto-signing";
|
|
2
2
|
import { MsgSend, MsgMultiSend } from "cosmjs-types/cosmos/bank/v1beta1/tx";
|
|
3
|
+
import { FirmaWalletService } from "../../FirmaWalletService";
|
|
3
4
|
import { ITxClient } from "../common/ITxClient";
|
|
4
5
|
export interface MsgSendEncodeObject extends EncodeObject {
|
|
5
6
|
readonly typeUrl: "/cosmos.bank.v1beta1.MsgSend";
|
|
@@ -10,7 +11,7 @@ export interface MsgMultiSendEncodeObject extends EncodeObject {
|
|
|
10
11
|
readonly value: Partial<MsgMultiSend>;
|
|
11
12
|
}
|
|
12
13
|
export declare class BankTxClient extends ITxClient {
|
|
13
|
-
constructor(wallet:
|
|
14
|
+
constructor(wallet: FirmaWalletService, address: string);
|
|
14
15
|
msgSend(data: MsgSend): MsgSendEncodeObject;
|
|
15
16
|
msgMultiSend(data: MsgMultiSend): MsgMultiSendEncodeObject;
|
|
16
17
|
}
|
|
@@ -1,12 +1,14 @@
|
|
|
1
|
-
import { Registry, EncodeObject
|
|
1
|
+
import { Registry, EncodeObject } from "@cosmjs/proto-signing";
|
|
2
2
|
import { SignAndBroadcastOptions } from ".";
|
|
3
3
|
import { TxRaw } from "cosmjs-types/cosmos/tx/v1beta1/tx";
|
|
4
4
|
import { BroadcastTxResponse } from "./stargateclient";
|
|
5
|
+
import { FirmaWalletService } from "../../FirmaWalletService";
|
|
5
6
|
export declare class ITxClient {
|
|
6
7
|
private readonly wallet;
|
|
7
8
|
private readonly serverUrl;
|
|
8
9
|
private readonly registry;
|
|
9
|
-
|
|
10
|
+
private rawWallet;
|
|
11
|
+
constructor(wallet: FirmaWalletService, serverUrl: string, registry: Registry);
|
|
10
12
|
sign(msgs: EncodeObject[], { fee, memo }: SignAndBroadcastOptions): Promise<TxRaw>;
|
|
11
13
|
broadcast(txRaw: TxRaw): Promise<BroadcastTxResponse>;
|
|
12
14
|
signAndBroadcast(msgs: EncodeObject[], { fee, memo }: SignAndBroadcastOptions): Promise<BroadcastTxResponse>;
|
|
@@ -44,6 +44,7 @@ var ITxClient = /** @class */ (function () {
|
|
|
44
44
|
this.wallet = wallet;
|
|
45
45
|
this.serverUrl = serverUrl;
|
|
46
46
|
this.registry = registry;
|
|
47
|
+
this.rawWallet = wallet.getRawWallet();
|
|
47
48
|
}
|
|
48
49
|
ITxClient.prototype.sign = function (msgs, _a) {
|
|
49
50
|
var fee = _a.fee, memo = _a.memo;
|
|
@@ -51,14 +52,17 @@ var ITxClient = /** @class */ (function () {
|
|
|
51
52
|
var client, address;
|
|
52
53
|
return __generator(this, function (_b) {
|
|
53
54
|
switch (_b.label) {
|
|
54
|
-
case 0:
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
55
|
+
case 0:
|
|
56
|
+
if (!this.wallet.isLedger()) return [3 /*break*/, 1];
|
|
57
|
+
return [2 /*return*/, this.wallet.signLedger(msgs, { fee: fee, memo: memo }, this.registry)];
|
|
58
|
+
case 1: return [4 /*yield*/, signingstargateclient_1.SigningStargateClient.connectWithSigner(this.serverUrl, this.rawWallet, this.registry)];
|
|
58
59
|
case 2:
|
|
60
|
+
client = _b.sent();
|
|
61
|
+
return [4 /*yield*/, this.rawWallet.getAccounts()];
|
|
62
|
+
case 3:
|
|
59
63
|
address = (_b.sent())[0].address;
|
|
60
64
|
return [4 /*yield*/, client.sign(address, msgs, fee, memo)];
|
|
61
|
-
case
|
|
65
|
+
case 4: return [2 /*return*/, _b.sent()];
|
|
62
66
|
}
|
|
63
67
|
});
|
|
64
68
|
});
|
|
@@ -68,7 +72,7 @@ var ITxClient = /** @class */ (function () {
|
|
|
68
72
|
var client, txBytes;
|
|
69
73
|
return __generator(this, function (_a) {
|
|
70
74
|
switch (_a.label) {
|
|
71
|
-
case 0: return [4 /*yield*/, signingstargateclient_1.SigningStargateClient.connectWithSigner(this.serverUrl, this.
|
|
75
|
+
case 0: return [4 /*yield*/, signingstargateclient_1.SigningStargateClient.connectWithSigner(this.serverUrl, this.rawWallet, this.registry)];
|
|
72
76
|
case 1:
|
|
73
77
|
client = _a.sent();
|
|
74
78
|
txBytes = tx_1.TxRaw.encode(txRaw).finish();
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { Tendermint34Client } from "@cosmjs/tendermint-rpc";
|
|
2
|
+
import { Account } from "./accounts";
|
|
3
|
+
import { StargateClient } from "./stargateclient";
|
|
4
|
+
export interface SignerData {
|
|
5
|
+
readonly account_number: string;
|
|
6
|
+
readonly sequence: string;
|
|
7
|
+
readonly chain_id: string;
|
|
8
|
+
}
|
|
9
|
+
export interface SequenceResponse {
|
|
10
|
+
readonly account_number: string;
|
|
11
|
+
readonly sequence: string;
|
|
12
|
+
}
|
|
13
|
+
export declare class LedgerSigningStargateClient extends StargateClient {
|
|
14
|
+
private chainId;
|
|
15
|
+
private static _endpoint;
|
|
16
|
+
static connectWithSigner(endpoint: string): Promise<LedgerSigningStargateClient>;
|
|
17
|
+
protected constructor(tmClient: Tendermint34Client);
|
|
18
|
+
getSignerData(address: string): Promise<SignerData>;
|
|
19
|
+
getChainId(): Promise<string>;
|
|
20
|
+
/**
|
|
21
|
+
* Takes a bech32 encoded address and returns the data part. The prefix is ignored and discarded.
|
|
22
|
+
* This is called AccAddress in Cosmos SDK, which is basically an alias for raw binary data.
|
|
23
|
+
* The result is typically 20 bytes long but not restricted to that.
|
|
24
|
+
*/
|
|
25
|
+
private toAccAddress;
|
|
26
|
+
getAccount(address: string): Promise<Account | undefined>;
|
|
27
|
+
}
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __extends = (this && this.__extends) || (function () {
|
|
3
|
+
var extendStatics = function (d, b) {
|
|
4
|
+
extendStatics = Object.setPrototypeOf ||
|
|
5
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
+
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
7
|
+
return extendStatics(d, b);
|
|
8
|
+
};
|
|
9
|
+
return function (d, b) {
|
|
10
|
+
if (typeof b !== "function" && b !== null)
|
|
11
|
+
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
12
|
+
extendStatics(d, b);
|
|
13
|
+
function __() { this.constructor = d; }
|
|
14
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
|
+
};
|
|
16
|
+
})();
|
|
17
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
18
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
19
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
20
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
21
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
22
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
23
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
24
|
+
});
|
|
25
|
+
};
|
|
26
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
27
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
28
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
29
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
30
|
+
function step(op) {
|
|
31
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
32
|
+
while (_) try {
|
|
33
|
+
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;
|
|
34
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
35
|
+
switch (op[0]) {
|
|
36
|
+
case 0: case 1: t = op; break;
|
|
37
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
38
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
39
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
40
|
+
default:
|
|
41
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
42
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
43
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
44
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
45
|
+
if (t[2]) _.ops.pop();
|
|
46
|
+
_.trys.pop(); continue;
|
|
47
|
+
}
|
|
48
|
+
op = body.call(thisArg, _);
|
|
49
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
50
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
54
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
55
|
+
};
|
|
56
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
57
|
+
exports.LedgerSigningStargateClient = void 0;
|
|
58
|
+
var encoding_1 = require("@cosmjs/encoding");
|
|
59
|
+
var tendermint_rpc_1 = require("@cosmjs/tendermint-rpc");
|
|
60
|
+
var accounts_1 = require("./accounts");
|
|
61
|
+
var stargateclient_1 = require("./stargateclient");
|
|
62
|
+
var axios_1 = __importDefault(require("axios"));
|
|
63
|
+
var any_1 = require("../google/protobuf/any");
|
|
64
|
+
var LedgerSigningStargateClient = /** @class */ (function (_super) {
|
|
65
|
+
__extends(LedgerSigningStargateClient, _super);
|
|
66
|
+
function LedgerSigningStargateClient(tmClient) {
|
|
67
|
+
return _super.call(this, tmClient) || this;
|
|
68
|
+
}
|
|
69
|
+
LedgerSigningStargateClient.connectWithSigner = function (endpoint) {
|
|
70
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
71
|
+
var tmClient;
|
|
72
|
+
return __generator(this, function (_a) {
|
|
73
|
+
switch (_a.label) {
|
|
74
|
+
case 0:
|
|
75
|
+
this._endpoint = endpoint;
|
|
76
|
+
return [4 /*yield*/, tendermint_rpc_1.Tendermint34Client.connect(endpoint)];
|
|
77
|
+
case 1:
|
|
78
|
+
tmClient = _a.sent();
|
|
79
|
+
return [2 /*return*/, new LedgerSigningStargateClient(tmClient)];
|
|
80
|
+
}
|
|
81
|
+
});
|
|
82
|
+
});
|
|
83
|
+
};
|
|
84
|
+
LedgerSigningStargateClient.prototype.getSignerData = function (address) {
|
|
85
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
86
|
+
var chainID, account;
|
|
87
|
+
return __generator(this, function (_a) {
|
|
88
|
+
switch (_a.label) {
|
|
89
|
+
case 0: return [4 /*yield*/, this.getChainId()];
|
|
90
|
+
case 1:
|
|
91
|
+
chainID = _a.sent();
|
|
92
|
+
return [4 /*yield*/, this.getAccount(address)];
|
|
93
|
+
case 2:
|
|
94
|
+
account = _a.sent();
|
|
95
|
+
if (account == null)
|
|
96
|
+
throw new Error("account is null");
|
|
97
|
+
return [2 /*return*/, { account_number: account.accountNumber.toString(), sequence: account.sequence.toString(), chain_id: chainID }];
|
|
98
|
+
}
|
|
99
|
+
});
|
|
100
|
+
});
|
|
101
|
+
};
|
|
102
|
+
LedgerSigningStargateClient.prototype.getChainId = function () {
|
|
103
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
104
|
+
var response, chainId;
|
|
105
|
+
return __generator(this, function (_a) {
|
|
106
|
+
switch (_a.label) {
|
|
107
|
+
case 0:
|
|
108
|
+
if (!!this.chainId) return [3 /*break*/, 2];
|
|
109
|
+
return [4 /*yield*/, this.forceGetTmClient().status()];
|
|
110
|
+
case 1:
|
|
111
|
+
response = _a.sent();
|
|
112
|
+
chainId = response.nodeInfo.network;
|
|
113
|
+
if (!chainId)
|
|
114
|
+
throw new Error("Chain ID must not be empty");
|
|
115
|
+
this.chainId = chainId;
|
|
116
|
+
_a.label = 2;
|
|
117
|
+
case 2: return [2 /*return*/, this.chainId];
|
|
118
|
+
}
|
|
119
|
+
});
|
|
120
|
+
});
|
|
121
|
+
};
|
|
122
|
+
/**
|
|
123
|
+
* Takes a bech32 encoded address and returns the data part. The prefix is ignored and discarded.
|
|
124
|
+
* This is called AccAddress in Cosmos SDK, which is basically an alias for raw binary data.
|
|
125
|
+
* The result is typically 20 bytes long but not restricted to that.
|
|
126
|
+
*/
|
|
127
|
+
LedgerSigningStargateClient.prototype.toAccAddress = function (address) {
|
|
128
|
+
return encoding_1.Bech32.decode(address).data;
|
|
129
|
+
};
|
|
130
|
+
LedgerSigningStargateClient.prototype.getAccount = function (address) {
|
|
131
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
132
|
+
var accAddress, hexAccAddress, axios, path, result, finalData, account, finalAccount, error_1;
|
|
133
|
+
return __generator(this, function (_a) {
|
|
134
|
+
switch (_a.label) {
|
|
135
|
+
case 0:
|
|
136
|
+
_a.trys.push([0, 2, , 3]);
|
|
137
|
+
accAddress = this.toAccAddress(address);
|
|
138
|
+
hexAccAddress = "0x01" + Buffer.from(accAddress).toString("hex");
|
|
139
|
+
axios = axios_1.default.create({
|
|
140
|
+
baseURL: LedgerSigningStargateClient._endpoint,
|
|
141
|
+
headers: {
|
|
142
|
+
Accept: "application/json",
|
|
143
|
+
},
|
|
144
|
+
timeout: 15000
|
|
145
|
+
});
|
|
146
|
+
path = "/abci_query?path=\"/store/acc/key\"";
|
|
147
|
+
return [4 /*yield*/, axios.get(path, { params: { data: hexAccAddress } })];
|
|
148
|
+
case 1:
|
|
149
|
+
result = _a.sent();
|
|
150
|
+
finalData = result.data.result.response.value;
|
|
151
|
+
account = any_1.Any.decode(Buffer.from(finalData, "base64"));
|
|
152
|
+
finalAccount = accounts_1.accountFromAny(account);
|
|
153
|
+
return [2 /*return*/, finalAccount];
|
|
154
|
+
case 2:
|
|
155
|
+
error_1 = _a.sent();
|
|
156
|
+
return [2 /*return*/, undefined];
|
|
157
|
+
case 3: return [2 /*return*/];
|
|
158
|
+
}
|
|
159
|
+
});
|
|
160
|
+
});
|
|
161
|
+
};
|
|
162
|
+
LedgerSigningStargateClient._endpoint = "";
|
|
163
|
+
return LedgerSigningStargateClient;
|
|
164
|
+
}(stargateclient_1.StargateClient));
|
|
165
|
+
exports.LedgerSigningStargateClient = LedgerSigningStargateClient;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { EncodeObject, Registry } from "@cosmjs/proto-signing";
|
|
2
|
+
import { TxRaw } from "cosmjs-types/cosmos/tx/v1beta1/tx";
|
|
3
|
+
import { SignAndBroadcastOptions } from "../common";
|
|
4
|
+
export interface LedgerWalletInterface {
|
|
5
|
+
getAddress(): Promise<string>;
|
|
6
|
+
sign(message: string): Promise<Uint8Array>;
|
|
7
|
+
getPublicKey(): Promise<Uint8Array>;
|
|
8
|
+
getAddressAndPublicKey(): Promise<{
|
|
9
|
+
address: string;
|
|
10
|
+
publicKey: Uint8Array;
|
|
11
|
+
}>;
|
|
12
|
+
showAddressOnDevice(): Promise<void>;
|
|
13
|
+
}
|
|
14
|
+
export declare function signFromLedger(ledger: LedgerWalletInterface, messages: EncodeObject[], option: SignAndBroadcastOptions, registry: Registry): Promise<TxRaw>;
|