@gnolang/tm2-js-client 1.3.1 → 1.3.3

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.
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  // Code generated by protoc-gen-ts_proto. DO NOT EDIT.
3
3
  // versions:
4
- // protoc-gen-ts_proto v2.7.5
4
+ // protoc-gen-ts_proto v2.7.7
5
5
  // protoc v5.29.3
6
6
  // source: google/protobuf/any.proto
7
7
  Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  // Code generated by protoc-gen-ts_proto. DO NOT EDIT.
3
3
  // versions:
4
- // protoc-gen-ts_proto v2.7.5
4
+ // protoc-gen-ts_proto v2.7.7
5
5
  // protoc v5.29.3
6
6
  // source: tm2/abci.proto
7
7
  var __importDefault = (this && this.__importDefault) || function (mod) {
@@ -0,0 +1,43 @@
1
+ import { BinaryReader, BinaryWriter } from '@bufbuild/protobuf/wire';
2
+ import Long from 'long';
3
+ import { Any } from '../google/protobuf/any';
4
+ export declare const protobufPackage = "tm";
5
+ /** messages */
6
+ export interface PubKeyMultisig {
7
+ k: Long;
8
+ pub_keys: Any[];
9
+ }
10
+ export interface Multisignature {
11
+ bit_array?: CompactBitArray | undefined;
12
+ sigs: Uint8Array[];
13
+ }
14
+ export interface CompactBitArray {
15
+ /** The number of extra bits in elems. */
16
+ extra_bits_stored: number;
17
+ elems: Uint8Array;
18
+ }
19
+ export declare const PubKeyMultisig: MessageFns<PubKeyMultisig>;
20
+ export declare const Multisignature: MessageFns<Multisignature>;
21
+ export declare const CompactBitArray: MessageFns<CompactBitArray>;
22
+ export declare function createCompactBitArray(bits: number): CompactBitArray;
23
+ export declare function compactBitArraySize(bA: CompactBitArray): number;
24
+ export declare function compactBitArraySetIndex(bA: CompactBitArray, i: number, v: boolean): boolean;
25
+ type Builtin = Date | Function | Uint8Array | string | number | boolean | undefined;
26
+ export type DeepPartial<T> = T extends Builtin ? T : T extends Long ? string | number | Long : T extends globalThis.Array<infer U> ? globalThis.Array<DeepPartial<U>> : T extends ReadonlyArray<infer U> ? ReadonlyArray<DeepPartial<U>> : T extends {} ? {
27
+ [K in keyof T]?: DeepPartial<T[K]>;
28
+ } : Partial<T>;
29
+ type KeysOfUnion<T> = T extends T ? keyof T : never;
30
+ export type Exact<P, I extends P> = P extends Builtin ? P : P & {
31
+ [K in keyof P]: Exact<P[K], I[K]>;
32
+ } & {
33
+ [K in Exclude<keyof I, KeysOfUnion<P>>]: never;
34
+ };
35
+ export interface MessageFns<T> {
36
+ encode(message: T, writer?: BinaryWriter): BinaryWriter;
37
+ decode(input: BinaryReader | Uint8Array, length?: number): T;
38
+ fromJSON(object: any): T;
39
+ toJSON(message: T): unknown;
40
+ create<I extends Exact<DeepPartial<T>, I>>(base?: I): T;
41
+ fromPartial<I extends Exact<DeepPartial<T>, I>>(object: I): T;
42
+ }
43
+ export {};
@@ -0,0 +1,322 @@
1
+ "use strict";
2
+ // Code generated by protoc-gen-ts_proto. DO NOT EDIT.
3
+ // versions:
4
+ // protoc-gen-ts_proto v2.7.7
5
+ // protoc v5.29.3
6
+ // source: tm2/multisig.proto
7
+ var __importDefault = (this && this.__importDefault) || function (mod) {
8
+ return (mod && mod.__esModule) ? mod : { "default": mod };
9
+ };
10
+ Object.defineProperty(exports, "__esModule", { value: true });
11
+ exports.CompactBitArray = exports.Multisignature = exports.PubKeyMultisig = exports.protobufPackage = void 0;
12
+ exports.createCompactBitArray = createCompactBitArray;
13
+ exports.compactBitArraySize = compactBitArraySize;
14
+ exports.compactBitArraySetIndex = compactBitArraySetIndex;
15
+ /* eslint-disable */
16
+ var wire_1 = require("@bufbuild/protobuf/wire");
17
+ var long_1 = __importDefault(require("long"));
18
+ var any_1 = require("../google/protobuf/any");
19
+ exports.protobufPackage = 'tm';
20
+ function createBasePubKeyMultisig() {
21
+ return { k: long_1.default.UZERO, pub_keys: [] };
22
+ }
23
+ exports.PubKeyMultisig = {
24
+ encode: function (message, writer) {
25
+ if (writer === void 0) { writer = new wire_1.BinaryWriter(); }
26
+ if (!message.k.equals(long_1.default.UZERO)) {
27
+ writer.uint32(8).uint64(message.k.toString());
28
+ }
29
+ for (var _i = 0, _a = message.pub_keys; _i < _a.length; _i++) {
30
+ var v = _a[_i];
31
+ any_1.Any.encode(v, writer.uint32(18).fork()).join();
32
+ }
33
+ return writer;
34
+ },
35
+ decode: function (input, length) {
36
+ var reader = input instanceof wire_1.BinaryReader ? input : new wire_1.BinaryReader(input);
37
+ var end = length === undefined ? reader.len : reader.pos + length;
38
+ var message = createBasePubKeyMultisig();
39
+ while (reader.pos < end) {
40
+ var tag = reader.uint32();
41
+ switch (tag >>> 3) {
42
+ case 1: {
43
+ if (tag !== 8) {
44
+ break;
45
+ }
46
+ message.k = long_1.default.fromString(reader.uint64().toString(), true);
47
+ continue;
48
+ }
49
+ case 2: {
50
+ if (tag !== 18) {
51
+ break;
52
+ }
53
+ message.pub_keys.push(any_1.Any.decode(reader, reader.uint32()));
54
+ continue;
55
+ }
56
+ }
57
+ if ((tag & 7) === 4 || tag === 0) {
58
+ break;
59
+ }
60
+ reader.skip(tag & 7);
61
+ }
62
+ return message;
63
+ },
64
+ fromJSON: function (object) {
65
+ return {
66
+ k: isSet(object.threshold)
67
+ ? long_1.default.fromValue(object.threshold)
68
+ : long_1.default.UZERO,
69
+ pub_keys: globalThis.Array.isArray(object === null || object === void 0 ? void 0 : object.pubkeys)
70
+ ? object.pubkeys.map(function (e) { return any_1.Any.fromJSON(e); })
71
+ : [],
72
+ };
73
+ },
74
+ toJSON: function (message) {
75
+ var _a;
76
+ var obj = {};
77
+ if (message.k !== undefined) {
78
+ obj.threshold = (message.k || long_1.default.UZERO).toString();
79
+ }
80
+ if ((_a = message.pub_keys) === null || _a === void 0 ? void 0 : _a.length) {
81
+ obj.pubkeys = message.pub_keys.map(function (e) { return any_1.Any.toJSON(e); });
82
+ }
83
+ return obj;
84
+ },
85
+ create: function (base) {
86
+ return exports.PubKeyMultisig.fromPartial(base !== null && base !== void 0 ? base : {});
87
+ },
88
+ fromPartial: function (object) {
89
+ var _a;
90
+ var message = createBasePubKeyMultisig();
91
+ message.k =
92
+ object.k !== undefined && object.k !== null
93
+ ? long_1.default.fromValue(object.k)
94
+ : long_1.default.UZERO;
95
+ message.pub_keys = ((_a = object.pub_keys) === null || _a === void 0 ? void 0 : _a.map(function (e) { return any_1.Any.fromPartial(e); })) || [];
96
+ return message;
97
+ },
98
+ };
99
+ function createBaseMultisignature() {
100
+ return { bit_array: undefined, sigs: [] };
101
+ }
102
+ exports.Multisignature = {
103
+ encode: function (message, writer) {
104
+ if (writer === void 0) { writer = new wire_1.BinaryWriter(); }
105
+ if (message.bit_array !== undefined) {
106
+ exports.CompactBitArray.encode(message.bit_array, writer.uint32(10).fork()).join();
107
+ }
108
+ for (var _i = 0, _a = message.sigs; _i < _a.length; _i++) {
109
+ var v = _a[_i];
110
+ writer.uint32(18).bytes(v);
111
+ }
112
+ return writer;
113
+ },
114
+ decode: function (input, length) {
115
+ var reader = input instanceof wire_1.BinaryReader ? input : new wire_1.BinaryReader(input);
116
+ var end = length === undefined ? reader.len : reader.pos + length;
117
+ var message = createBaseMultisignature();
118
+ while (reader.pos < end) {
119
+ var tag = reader.uint32();
120
+ switch (tag >>> 3) {
121
+ case 1: {
122
+ if (tag !== 10) {
123
+ break;
124
+ }
125
+ message.bit_array = exports.CompactBitArray.decode(reader, reader.uint32());
126
+ continue;
127
+ }
128
+ case 2: {
129
+ if (tag !== 18) {
130
+ break;
131
+ }
132
+ message.sigs.push(reader.bytes());
133
+ continue;
134
+ }
135
+ }
136
+ if ((tag & 7) === 4 || tag === 0) {
137
+ break;
138
+ }
139
+ reader.skip(tag & 7);
140
+ }
141
+ return message;
142
+ },
143
+ fromJSON: function (object) {
144
+ return {
145
+ bit_array: isSet(object.bit_array)
146
+ ? exports.CompactBitArray.fromJSON(object.bit_array)
147
+ : undefined,
148
+ sigs: globalThis.Array.isArray(object === null || object === void 0 ? void 0 : object.sigs)
149
+ ? object.sigs.map(function (e) { return bytesFromBase64(e); })
150
+ : [],
151
+ };
152
+ },
153
+ toJSON: function (message) {
154
+ var _a;
155
+ var obj = {};
156
+ if (message.bit_array !== undefined) {
157
+ obj.bit_array = exports.CompactBitArray.toJSON(message.bit_array);
158
+ }
159
+ if ((_a = message.sigs) === null || _a === void 0 ? void 0 : _a.length) {
160
+ obj.sigs = message.sigs.map(function (e) { return base64FromBytes(e); });
161
+ }
162
+ return obj;
163
+ },
164
+ create: function (base) {
165
+ return exports.Multisignature.fromPartial(base !== null && base !== void 0 ? base : {});
166
+ },
167
+ fromPartial: function (object) {
168
+ var _a;
169
+ var message = createBaseMultisignature();
170
+ message.bit_array =
171
+ object.bit_array !== undefined && object.bit_array !== null
172
+ ? exports.CompactBitArray.fromPartial(object.bit_array)
173
+ : undefined;
174
+ message.sigs = ((_a = object.sigs) === null || _a === void 0 ? void 0 : _a.map(function (e) { return e; })) || [];
175
+ return message;
176
+ },
177
+ };
178
+ function createBaseCompactBitArray() {
179
+ return { extra_bits_stored: 0, elems: new Uint8Array(0) };
180
+ }
181
+ exports.CompactBitArray = {
182
+ encode: function (message, writer) {
183
+ if (writer === void 0) { writer = new wire_1.BinaryWriter(); }
184
+ if (message.extra_bits_stored !== 0) {
185
+ writer.uint32(8).uint32(message.extra_bits_stored);
186
+ }
187
+ if (message.elems.length !== 0) {
188
+ writer.uint32(18).bytes(message.elems);
189
+ }
190
+ return writer;
191
+ },
192
+ decode: function (input, length) {
193
+ var reader = input instanceof wire_1.BinaryReader ? input : new wire_1.BinaryReader(input);
194
+ var end = length === undefined ? reader.len : reader.pos + length;
195
+ var message = createBaseCompactBitArray();
196
+ while (reader.pos < end) {
197
+ var tag = reader.uint32();
198
+ switch (tag >>> 3) {
199
+ case 1: {
200
+ if (tag !== 8) {
201
+ break;
202
+ }
203
+ message.extra_bits_stored = reader.uint32();
204
+ continue;
205
+ }
206
+ case 2: {
207
+ if (tag !== 18) {
208
+ break;
209
+ }
210
+ message.elems = reader.bytes();
211
+ continue;
212
+ }
213
+ }
214
+ if ((tag & 7) === 4 || tag === 0) {
215
+ break;
216
+ }
217
+ reader.skip(tag & 7);
218
+ }
219
+ return message;
220
+ },
221
+ fromJSON: function (json) {
222
+ if (json === null) {
223
+ // Handle null case
224
+ return createBaseCompactBitArray();
225
+ }
226
+ if (typeof json !== 'string') {
227
+ throw new Error("CompactBitArray in JSON should be a string or null but got ".concat(typeof json));
228
+ }
229
+ var bits = json;
230
+ var numBits = bits.length;
231
+ // Create a new CompactBitArray
232
+ var numBytes = Math.ceil(numBits / 8);
233
+ var elems = new Uint8Array(numBytes);
234
+ var extraBitsStored = numBits % 8;
235
+ var bitArray = { extra_bits_stored: extraBitsStored, elems: elems };
236
+ // Set bits based on the string representation
237
+ for (var i = 0; i < numBits; i++) {
238
+ if (bits[i] === 'x') {
239
+ compactBitArraySetIndex(bitArray, i, true);
240
+ }
241
+ // For '_', we don't need to do anything as bits are initialized to 0
242
+ }
243
+ return bitArray;
244
+ },
245
+ toJSON: function (message) {
246
+ throw new Error('not implemented');
247
+ },
248
+ create: function (base) {
249
+ return exports.CompactBitArray.fromPartial(base !== null && base !== void 0 ? base : {});
250
+ },
251
+ fromPartial: function (object) {
252
+ var _a, _b;
253
+ var message = createBaseCompactBitArray();
254
+ message.extra_bits_stored = (_a = object.extra_bits_stored) !== null && _a !== void 0 ? _a : 0;
255
+ message.elems = (_b = object.elems) !== null && _b !== void 0 ? _b : new Uint8Array(0);
256
+ return message;
257
+ },
258
+ };
259
+ function createCompactBitArray(bits) {
260
+ if (bits <= 0) {
261
+ throw new Error('empty');
262
+ }
263
+ var extraBitsStored = bits % 8;
264
+ var elems = new Uint8Array(Math.ceil(bits / 8));
265
+ return { extra_bits_stored: extraBitsStored, elems: elems };
266
+ }
267
+ function compactBitArraySize(bA) {
268
+ if (bA.elems === null) {
269
+ return 0;
270
+ }
271
+ else if (bA.extra_bits_stored === 0) {
272
+ return bA.elems.length * 8;
273
+ }
274
+ return (bA.elems.length - 1) * 8 + bA.extra_bits_stored;
275
+ }
276
+ // SetIndex sets the bit at index i within the bit array
277
+ // Returns true if successful, false if out of bounds or array is null
278
+ function compactBitArraySetIndex(bA, i, v) {
279
+ if (bA.elems === null) {
280
+ return false;
281
+ }
282
+ if (i >= compactBitArraySize(bA)) {
283
+ return false;
284
+ }
285
+ if (v) {
286
+ // Set the bit (most significant bit first)
287
+ bA.elems[i >> 3] |= 1 << (7 - (i % 8));
288
+ }
289
+ else {
290
+ // Clear the bit
291
+ bA.elems[i >> 3] &= ~(1 << (7 - (i % 8)));
292
+ }
293
+ return true;
294
+ }
295
+ function bytesFromBase64(b64) {
296
+ if (globalThis.Buffer) {
297
+ return Uint8Array.from(globalThis.Buffer.from(b64, 'base64'));
298
+ }
299
+ else {
300
+ var bin = globalThis.atob(b64);
301
+ var arr = new Uint8Array(bin.length);
302
+ for (var i = 0; i < bin.length; ++i) {
303
+ arr[i] = bin.charCodeAt(i);
304
+ }
305
+ return arr;
306
+ }
307
+ }
308
+ function base64FromBytes(arr) {
309
+ if (globalThis.Buffer) {
310
+ return globalThis.Buffer.from(arr).toString('base64');
311
+ }
312
+ else {
313
+ var bin_1 = [];
314
+ arr.forEach(function (byte) {
315
+ bin_1.push(globalThis.String.fromCharCode(byte));
316
+ });
317
+ return globalThis.btoa(bin_1.join(''));
318
+ }
319
+ }
320
+ function isSet(value) {
321
+ return value !== null && value !== undefined;
322
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,63 @@
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 = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
13
+ return g.next = verb(0), g["throw"] = verb(1), g["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 utils_1 = require("@noble/hashes/utils");
40
+ var multisig_1 = require("./multisig");
41
+ describe('TestMarshalCompactBitArrayAmino', function () {
42
+ var testCases = [
43
+ { marshalledBA: "null", hexOutput: '' },
44
+ { marshalledBA: "null", hexOutput: '' },
45
+ { marshalledBA: "\"_\"", hexOutput: '0801120100' },
46
+ { marshalledBA: "\"x\"", hexOutput: '0801120180' },
47
+ { marshalledBA: "\"xx___\"", hexOutput: '08051201c0' },
48
+ { marshalledBA: "\"xx______x\"", hexOutput: '08011202c080' },
49
+ { marshalledBA: "\"xx_____________x\"", hexOutput: '1202c001' },
50
+ ];
51
+ test.each(testCases)('$marshalledBA', function (_a) { return __awaiter(void 0, [_a], void 0, function (_b) {
52
+ var jsonData, bA, bz, actualHex;
53
+ var marshalledBA = _b.marshalledBA, hexOutput = _b.hexOutput;
54
+ return __generator(this, function (_c) {
55
+ jsonData = JSON.parse(marshalledBA);
56
+ bA = multisig_1.CompactBitArray.fromJSON(jsonData);
57
+ bz = multisig_1.CompactBitArray.encode(bA).finish();
58
+ actualHex = (0, utils_1.bytesToHex)(bz);
59
+ expect(actualHex).toBe(hexOutput);
60
+ return [2 /*return*/];
61
+ });
62
+ }); });
63
+ });
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  // Code generated by protoc-gen-ts_proto. DO NOT EDIT.
3
3
  // versions:
4
- // protoc-gen-ts_proto v2.7.5
4
+ // protoc-gen-ts_proto v2.7.7
5
5
  // protoc v5.29.3
6
6
  // source: tm2/tx.proto
7
7
  var __importDefault = (this && this.__importDefault) || function (mod) {
@@ -1,6 +1,6 @@
1
1
  import { Tx } from '../../proto';
2
2
  import { Provider } from '../provider';
3
- import { BlockInfo, BlockResult, BroadcastTransactionMap, ConsensusParams, NetworkInfo, Status, TxResult } from '../types';
3
+ import { ABCIAccount, BlockInfo, BlockResult, BroadcastTransactionMap, ConsensusParams, NetworkInfo, Status, TxResult } from '../types';
4
4
  /**
5
5
  * Provider based on JSON-RPC HTTP requests
6
6
  */
@@ -21,6 +21,7 @@ export declare class JSONRPCProvider implements Provider {
21
21
  getNetwork(): Promise<NetworkInfo>;
22
22
  getAccountSequence(address: string, height?: number): Promise<number>;
23
23
  getAccountNumber(address: string, height?: number): Promise<number>;
24
+ getAccount(address: string, height?: number): Promise<ABCIAccount>;
24
25
  getStatus(): Promise<Status>;
25
26
  getTransaction(hash: string): Promise<TxResult>;
26
27
  sendTransaction<K extends keyof BroadcastTransactionMap>(tx: string, endpoint: K): Promise<BroadcastTransactionMap[K]['result']>;
@@ -203,12 +203,32 @@ var JSONRPCProvider = /** @class */ (function () {
203
203
  });
204
204
  });
205
205
  };
206
+ JSONRPCProvider.prototype.getAccount = function (address, height) {
207
+ return __awaiter(this, void 0, void 0, function () {
208
+ var abciResponse;
209
+ return __generator(this, function (_a) {
210
+ switch (_a.label) {
211
+ case 0: return [4 /*yield*/, services_1.RestService.post(this.baseURL, {
212
+ request: (0, utility_1.newRequest)(endpoints_1.ABCIEndpoint.ABCI_QUERY, [
213
+ "auth/accounts/".concat(address),
214
+ '',
215
+ '0', // Height; not supported > 0 for now
216
+ false,
217
+ ]),
218
+ })];
219
+ case 1:
220
+ abciResponse = _a.sent();
221
+ return [2 /*return*/, (0, utility_1.extractAccountFromResponse)(abciResponse.response.ResponseBase.Data)];
222
+ }
223
+ });
224
+ });
225
+ };
206
226
  JSONRPCProvider.prototype.getStatus = function () {
207
227
  return __awaiter(this, void 0, void 0, function () {
208
228
  return __generator(this, function (_a) {
209
229
  switch (_a.label) {
210
230
  case 0: return [4 /*yield*/, services_1.RestService.post(this.baseURL, {
211
- request: (0, utility_1.newRequest)(endpoints_1.CommonEndpoint.STATUS),
231
+ request: (0, utility_1.newRequest)(endpoints_1.CommonEndpoint.STATUS, [null]),
212
232
  })];
213
233
  case 1: return [2 /*return*/, _a.sent()];
214
234
  }
@@ -437,4 +437,52 @@ describe('JSON-RPC Provider', function () {
437
437
  });
438
438
  }); });
439
439
  });
440
+ describe('getAccount', function () {
441
+ var validAccount = {
442
+ BaseAccount: {
443
+ address: 'random address',
444
+ coins: '',
445
+ public_key: { '@type': 'pktype', value: 'pk' },
446
+ account_number: '10',
447
+ sequence: '42',
448
+ },
449
+ };
450
+ test.each([
451
+ [JSON.stringify(validAccount), validAccount], // account exists
452
+ ['null', null], // account doesn't exist
453
+ ])('case %#', function (response, expected) { return __awaiter(void 0, void 0, void 0, function () {
454
+ var mockABCIResponse, provider, account, e_3;
455
+ return __generator(this, function (_a) {
456
+ switch (_a.label) {
457
+ case 0:
458
+ mockABCIResponse = (0, jest_mock_extended_1.mock)();
459
+ mockABCIResponse.response.ResponseBase = {
460
+ Log: '',
461
+ Info: '',
462
+ Data: (0, utility_1.stringToBase64)(response),
463
+ Error: null,
464
+ Events: null,
465
+ };
466
+ mockedAxios.post.mockResolvedValue({
467
+ data: (0, utility_1.newResponse)(mockABCIResponse),
468
+ });
469
+ _a.label = 1;
470
+ case 1:
471
+ _a.trys.push([1, 3, , 4]);
472
+ provider = new jsonrpc_1.JSONRPCProvider(mockURL);
473
+ return [4 /*yield*/, provider.getAccount('address')];
474
+ case 2:
475
+ account = _a.sent();
476
+ expect(axios_1.default.post).toHaveBeenCalled();
477
+ expect(account).toStrictEqual(expected);
478
+ return [3 /*break*/, 4];
479
+ case 3:
480
+ e_3 = _a.sent();
481
+ expect(e_3.message).toContain('account is not initialized');
482
+ return [3 /*break*/, 4];
483
+ case 4: return [2 /*return*/];
484
+ }
485
+ });
486
+ }); });
487
+ });
440
488
  });
@@ -1,4 +1,4 @@
1
- import { BlockInfo, BlockResult, BroadcastAsGeneric, BroadcastTransactionMap, ConsensusParams, NetworkInfo, Status } from './types';
1
+ import { ABCIAccount, BlockInfo, BlockResult, BroadcastAsGeneric, BroadcastTransactionMap, ConsensusParams, NetworkInfo, Status } from './types';
2
2
  import { Tx } from '../proto';
3
3
  /**
4
4
  * Read-only abstraction for accessing blockchain data
@@ -17,6 +17,7 @@ export interface Provider {
17
17
  * @param {string} address the bech32 address of the account
18
18
  * @param {number} [height=0] the height for querying.
19
19
  * If omitted, the latest height is used.
20
+ * @deprecated use {@link getAccount} instead
20
21
  */
21
22
  getAccountSequence(address: string, height?: number): Promise<number>;
22
23
  /**
@@ -25,8 +26,17 @@ export interface Provider {
25
26
  * @param {string} address the bech32 address of the account
26
27
  * @param {number} [height=0] the height for querying.
27
28
  * If omitted, the latest height is used
29
+ * @deprecated use {@link getAccount} instead
28
30
  */
29
31
  getAccountNumber(address: string, height?: number): Promise<number>;
32
+ /**
33
+ * Fetches the account. Errors out if the account
34
+ * is not initialized
35
+ * @param {string} address the bech32 address of the account
36
+ * @param {number} [height=0] the height for querying.
37
+ * If omitted, the latest height is used
38
+ */
39
+ getAccount(address: string, height?: number): Promise<ABCIAccount>;
30
40
  /**
31
41
  * Fetches the block at the specific height, if any
32
42
  * @param {number} height the height for querying
@@ -1,7 +1,7 @@
1
1
  import { Tx } from '../../proto';
2
2
  import { ResponseDeliverTx } from '../../proto/tm2/abci';
3
3
  import { Provider } from '../provider';
4
- import { ABCIResponse } from '../types';
4
+ import { ABCIAccount, ABCIResponse } from '../types';
5
5
  /**
6
6
  * Extracts the specific balance denomination from the ABCI response
7
7
  * @param {string | null} abciData the base64-encoded ABCI data
@@ -18,6 +18,11 @@ export declare const extractSequenceFromResponse: (abciData: string | null) => n
18
18
  * @param {string | null} abciData the base64-encoded ABCI data
19
19
  */
20
20
  export declare const extractAccountNumberFromResponse: (abciData: string | null) => number;
21
+ /**
22
+ * Extracts the account from the ABCI response
23
+ * @param {string | null} abciData the base64-encoded ABCI data
24
+ */
25
+ export declare const extractAccountFromResponse: (abciData: string | null) => ABCIAccount;
21
26
  /**
22
27
  * Extracts the simulate transaction response from the ABCI response value
23
28
  * @param {string | null} abciData the base64-encoded ResponseDeliverTx proto message
@@ -36,7 +36,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
36
36
  }
37
37
  };
38
38
  Object.defineProperty(exports, "__esModule", { value: true });
39
- exports.waitForTransaction = exports.extractSimulateFromResponse = exports.extractAccountNumberFromResponse = exports.extractSequenceFromResponse = exports.extractBalanceFromResponse = void 0;
39
+ exports.waitForTransaction = exports.extractSimulateFromResponse = exports.extractAccountFromResponse = exports.extractAccountNumberFromResponse = exports.extractSequenceFromResponse = exports.extractBalanceFromResponse = void 0;
40
40
  var crypto_1 = require("@cosmjs/crypto");
41
41
  var proto_1 = require("../../proto");
42
42
  var abci_1 = require("../../proto/tm2/abci");
@@ -115,6 +115,25 @@ var extractAccountNumberFromResponse = function (abciData) {
115
115
  }
116
116
  };
117
117
  exports.extractAccountNumberFromResponse = extractAccountNumberFromResponse;
118
+ /**
119
+ * Extracts the account from the ABCI response
120
+ * @param {string | null} abciData the base64-encoded ABCI data
121
+ */
122
+ var extractAccountFromResponse = function (abciData) {
123
+ // Make sure the response is initialized
124
+ if (!abciData) {
125
+ throw new Error('account is not initialized');
126
+ }
127
+ try {
128
+ // Parse the account
129
+ var account = (0, requests_utility_1.parseABCI)(abciData);
130
+ return account;
131
+ }
132
+ catch (e) {
133
+ throw new Error('account is not initialized');
134
+ }
135
+ };
136
+ exports.extractAccountFromResponse = extractAccountFromResponse;
118
137
  /**
119
138
  * Extracts the simulate transaction response from the ABCI response value
120
139
  * @param {string | null} abciData the base64-encoded ResponseDeliverTx proto message
@@ -1,6 +1,6 @@
1
1
  import { Tx } from '../../proto';
2
2
  import { Provider } from '../provider';
3
- import { BlockInfo, BlockResult, BroadcastTransactionMap, ConsensusParams, NetworkInfo, RPCRequest, RPCResponse, Status, TxResult } from '../types';
3
+ import { ABCIAccount, BlockInfo, BlockResult, BroadcastTransactionMap, ConsensusParams, NetworkInfo, RPCRequest, RPCResponse, Status, TxResult } from '../types';
4
4
  /**
5
5
  * Provider based on WS JSON-RPC HTTP requests
6
6
  */
@@ -48,6 +48,7 @@ export declare class WSProvider implements Provider {
48
48
  getNetwork(): Promise<NetworkInfo>;
49
49
  getAccountSequence(address: string, height?: number): Promise<number>;
50
50
  getAccountNumber(address: string, height?: number): Promise<number>;
51
+ getAccount(address: string, height?: number): Promise<ABCIAccount>;
51
52
  getStatus(): Promise<Status>;
52
53
  getTransaction(hash: string): Promise<TxResult>;
53
54
  sendTransaction<K extends keyof BroadcastTransactionMap>(tx: string, endpoint: K): Promise<BroadcastTransactionMap[K]['result']>;
@@ -296,12 +296,31 @@ var WSProvider = /** @class */ (function () {
296
296
  });
297
297
  });
298
298
  };
299
+ WSProvider.prototype.getAccount = function (address, height) {
300
+ return __awaiter(this, void 0, void 0, function () {
301
+ var response, abciResponse;
302
+ return __generator(this, function (_a) {
303
+ switch (_a.label) {
304
+ case 0: return [4 /*yield*/, this.sendRequest((0, utility_1.newRequest)(endpoints_1.ABCIEndpoint.ABCI_QUERY, [
305
+ "auth/accounts/".concat(address),
306
+ '',
307
+ '0', // Height; not supported > 0 for now
308
+ false,
309
+ ]))];
310
+ case 1:
311
+ response = _a.sent();
312
+ abciResponse = this.parseResponse(response);
313
+ return [2 /*return*/, (0, utility_1.extractAccountFromResponse)(abciResponse.response.ResponseBase.Data)];
314
+ }
315
+ });
316
+ });
317
+ };
299
318
  WSProvider.prototype.getStatus = function () {
300
319
  return __awaiter(this, void 0, void 0, function () {
301
320
  var response;
302
321
  return __generator(this, function (_a) {
303
322
  switch (_a.label) {
304
- case 0: return [4 /*yield*/, this.sendRequest((0, utility_1.newRequest)(endpoints_1.CommonEndpoint.STATUS))];
323
+ case 0: return [4 /*yield*/, this.sendRequest((0, utility_1.newRequest)(endpoints_1.CommonEndpoint.STATUS, [null]))];
305
324
  case 1:
306
325
  response = _a.sent();
307
326
  return [2 /*return*/, this.parseResponse(response)];
@@ -336,6 +336,47 @@ describe('WS Provider', function () {
336
336
  });
337
337
  }); });
338
338
  });
339
+ describe('getAccount', function () {
340
+ var validAccount = {
341
+ BaseAccount: {
342
+ address: 'random address',
343
+ coins: '',
344
+ public_key: null,
345
+ account_number: '10',
346
+ sequence: '0',
347
+ },
348
+ };
349
+ test.each([
350
+ [JSON.stringify(validAccount), validAccount], // account exists
351
+ ['null', null], // account doesn't exist
352
+ ])('case %#', function (response, expected) { return __awaiter(void 0, void 0, void 0, function () {
353
+ var mockResponse, account, e_2;
354
+ return __generator(this, function (_a) {
355
+ switch (_a.label) {
356
+ case 0:
357
+ mockResponse = mockABCIResponse(response);
358
+ // Set the response
359
+ return [4 /*yield*/, setHandler(mockResponse)];
360
+ case 1:
361
+ // Set the response
362
+ _a.sent();
363
+ _a.label = 2;
364
+ case 2:
365
+ _a.trys.push([2, 4, , 5]);
366
+ return [4 /*yield*/, wsProvider.getAccount('address')];
367
+ case 3:
368
+ account = _a.sent();
369
+ expect(account).toStrictEqual(expected);
370
+ return [3 /*break*/, 5];
371
+ case 4:
372
+ e_2 = _a.sent();
373
+ expect(e_2.message).toContain('account is not initialized');
374
+ return [3 /*break*/, 5];
375
+ case 5: return [2 /*return*/];
376
+ }
377
+ });
378
+ }); });
379
+ });
339
380
  describe('getBalance', function () {
340
381
  var denomination = 'atom';
341
382
  test.each([
@@ -405,7 +446,7 @@ describe('WS Provider', function () {
405
446
  [validResult, validResult.hash, '', ''], // no error
406
447
  [invalidResult, invalidResult.hash, messages_1.UnauthorizedErrorMessage, mockLog], // error out
407
448
  ])('case %#', function (response, expectedHash, expectedErr, expectedLog) { return __awaiter(void 0, void 0, void 0, function () {
408
- var tx, e_2;
449
+ var tx, e_3;
409
450
  return __generator(this, function (_a) {
410
451
  switch (_a.label) {
411
452
  case 0: return [4 /*yield*/, setHandler(response)];
@@ -423,9 +464,9 @@ describe('WS Provider', function () {
423
464
  }
424
465
  return [3 /*break*/, 5];
425
466
  case 4:
426
- e_2 = _a.sent();
427
- expect(e_2.message).toBe(expectedErr);
428
- expect(e_2.log).toBe(expectedLog);
467
+ e_3 = _a.sent();
468
+ expect(e_3.message).toBe(expectedErr);
469
+ expect(e_3.log).toBe(expectedLog);
429
470
  return [3 /*break*/, 5];
430
471
  case 5: return [2 /*return*/];
431
472
  }
@@ -3,6 +3,10 @@ import { Signer } from './signer';
3
3
  import { LedgerConnector } from '@cosmjs/ledger-amino';
4
4
  import { Any, Tx } from '../proto';
5
5
  import { AccountWalletOption, CreateWalletOptions } from './types';
6
+ export interface SignTransactionOptions {
7
+ accountNumber?: string;
8
+ sequence?: string;
9
+ }
6
10
  /**
7
11
  * Wallet is a single account abstraction
8
12
  * that can interact with the blockchain
@@ -85,7 +89,7 @@ export declare class Wallet {
85
89
  * the transaction sign bytes are generated using sorted JSON, which requires
86
90
  * encoded message values to be decoded for sorting
87
91
  */
88
- signTransaction: (tx: Tx, decodeTxMessages: (messages: Any[]) => any[]) => Promise<Tx>;
92
+ signTransaction: (tx: Tx, decodeTxMessages: (messages: Any[]) => any[], opts?: SignTransactionOptions) => Promise<Tx>;
89
93
  /**
90
94
  * Encodes and sends the transaction. If the type of endpoint
91
95
  * is a broadcast commit, waits for the transaction to be committed to the chain.
@@ -182,8 +182,8 @@ var Wallet = /** @class */ (function () {
182
182
  * the transaction sign bytes are generated using sorted JSON, which requires
183
183
  * encoded message values to be decoded for sorting
184
184
  */
185
- this.signTransaction = function (tx, decodeTxMessages) { return __awaiter(_this, void 0, void 0, function () {
186
- var status, chainID, address, accountNumber, accountSequence, publicKey, signPayload, signBytes, wrappedKey, txSignature;
185
+ this.signTransaction = function (tx, decodeTxMessages, opts) { return __awaiter(_this, void 0, void 0, function () {
186
+ var status, chainID, accountNumber, accountSequence, address, account, publicKey, signPayload, signBytes, wrappedKey, txSignature;
187
187
  var _b;
188
188
  return __generator(this, function (_c) {
189
189
  switch (_c.label) {
@@ -199,22 +199,29 @@ var Wallet = /** @class */ (function () {
199
199
  case 1:
200
200
  status = _c.sent();
201
201
  chainID = status.node_info.network;
202
+ accountNumber = opts === null || opts === void 0 ? void 0 : opts.accountNumber;
203
+ accountSequence = opts === null || opts === void 0 ? void 0 : opts.sequence;
204
+ if (!(accountNumber === undefined || accountSequence === undefined)) return [3 /*break*/, 4];
202
205
  return [4 /*yield*/, this.getAddress()];
203
206
  case 2:
204
207
  address = _c.sent();
205
- return [4 /*yield*/, this.provider.getAccountNumber(address)];
208
+ return [4 /*yield*/, this.provider.getAccount(address)];
206
209
  case 3:
207
- accountNumber = _c.sent();
208
- return [4 /*yield*/, this.provider.getAccountSequence(address)];
209
- case 4:
210
- accountSequence = _c.sent();
211
- return [4 /*yield*/, this.signer.getPublicKey()];
210
+ account = _c.sent();
211
+ if (accountNumber === undefined) {
212
+ accountNumber = account.BaseAccount.account_number;
213
+ }
214
+ if (accountSequence === undefined) {
215
+ accountSequence = account.BaseAccount.sequence;
216
+ }
217
+ _c.label = 4;
218
+ case 4: return [4 /*yield*/, this.signer.getPublicKey()];
212
219
  case 5:
213
220
  publicKey = _c.sent();
214
221
  signPayload = {
215
222
  chain_id: chainID,
216
- account_number: accountNumber.toString(10),
217
- sequence: accountSequence.toString(10),
223
+ account_number: accountNumber,
224
+ sequence: accountSequence,
218
225
  fee: {
219
226
  gas_fee: tx.fee.gas_fee,
220
227
  gas_wanted: tx.fee.gas_wanted.toString(10),
@@ -246,7 +246,7 @@ describe('Wallet', function () {
246
246
  });
247
247
  }); });
248
248
  test('signTransaction', function () { return __awaiter(void 0, void 0, void 0, function () {
249
- var mockTx, mockStatus, mockProvider, wallet, emptyDecodeCallback, signedTx, sig;
249
+ var mockTx, mockStatus, mockProvider, mockAccount, wallet, emptyDecodeCallback, signedTx, sig;
250
250
  var _a, _b;
251
251
  return __generator(this, function (_c) {
252
252
  switch (_c.label) {
@@ -274,8 +274,16 @@ describe('Wallet', function () {
274
274
  };
275
275
  mockProvider = (0, jest_mock_extended_1.mock)();
276
276
  mockProvider.getStatus.mockResolvedValue(mockStatus);
277
- mockProvider.getAccountNumber.mockResolvedValue(10);
278
- mockProvider.getAccountSequence.mockResolvedValue(10);
277
+ mockAccount = {
278
+ BaseAccount: {
279
+ address: '',
280
+ coins: '',
281
+ public_key: null,
282
+ account_number: '',
283
+ sequence: '',
284
+ },
285
+ };
286
+ mockProvider.getAccount.mockResolvedValue(mockAccount);
279
287
  return [4 /*yield*/, wallet_1.Wallet.createRandom()];
280
288
  case 1:
281
289
  wallet = _c.sent();
@@ -287,8 +295,71 @@ describe('Wallet', function () {
287
295
  case 2:
288
296
  signedTx = _c.sent();
289
297
  expect(mockProvider.getStatus).toHaveBeenCalled();
290
- expect(mockProvider.getAccountNumber).toHaveBeenCalled();
291
- expect(mockProvider.getAccountSequence).toHaveBeenCalled();
298
+ expect(mockProvider.getAccount).toHaveBeenCalled();
299
+ expect(signedTx.signatures).toHaveLength(1);
300
+ sig = signedTx.signatures[0];
301
+ expect((_a = sig.pub_key) === null || _a === void 0 ? void 0 : _a.type_url).toBe(types_1.Secp256k1PubKeyType);
302
+ expect((_b = sig.pub_key) === null || _b === void 0 ? void 0 : _b.value).not.toBeNull();
303
+ expect(sig.signature).not.toBeNull();
304
+ return [2 /*return*/];
305
+ }
306
+ });
307
+ }); });
308
+ test('signTransactionWithAllOpts', function () { return __awaiter(void 0, void 0, void 0, function () {
309
+ var mockTx, opts, mockStatus, mockProvider, mockAccount, wallet, emptyDecodeCallback, signedTx, sig;
310
+ var _a, _b;
311
+ return __generator(this, function (_c) {
312
+ switch (_c.label) {
313
+ case 0:
314
+ mockTx = (0, jest_mock_extended_1.mock)();
315
+ mockTx.signatures = [];
316
+ mockTx.fee = {
317
+ gas_fee: '10',
318
+ gas_wanted: new long_1.default(10),
319
+ };
320
+ mockTx.messages = [];
321
+ opts = {
322
+ accountNumber: '42',
323
+ sequence: '42',
324
+ };
325
+ mockStatus = (0, jest_mock_extended_1.mock)();
326
+ mockStatus.node_info = {
327
+ version_set: [],
328
+ version: '',
329
+ net_address: '',
330
+ software: '',
331
+ channels: '',
332
+ monkier: '',
333
+ other: {
334
+ tx_index: '',
335
+ rpc_address: '',
336
+ },
337
+ network: 'testchain',
338
+ };
339
+ mockProvider = (0, jest_mock_extended_1.mock)();
340
+ mockProvider.getStatus.mockResolvedValue(mockStatus);
341
+ mockAccount = {
342
+ BaseAccount: {
343
+ address: '',
344
+ coins: '',
345
+ public_key: null,
346
+ account_number: '',
347
+ sequence: '',
348
+ },
349
+ };
350
+ mockProvider.getAccount.mockResolvedValue(mockAccount);
351
+ return [4 /*yield*/, wallet_1.Wallet.createRandom()];
352
+ case 1:
353
+ wallet = _c.sent();
354
+ wallet.connect(mockProvider);
355
+ emptyDecodeCallback = function (_) {
356
+ return [];
357
+ };
358
+ return [4 /*yield*/, wallet.signTransaction(mockTx, emptyDecodeCallback, opts)];
359
+ case 2:
360
+ signedTx = _c.sent();
361
+ expect(mockProvider.getStatus).toHaveBeenCalled();
362
+ expect(mockProvider.getAccount).not.toHaveBeenCalled();
292
363
  expect(signedTx.signatures).toHaveLength(1);
293
364
  sig = signedTx.signatures[0];
294
365
  expect((_a = sig.pub_key) === null || _a === void 0 ? void 0 : _a.type_url).toBe(types_1.Secp256k1PubKeyType);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gnolang/tm2-js-client",
3
- "version": "1.3.1",
3
+ "version": "1.3.3",
4
4
  "description": "Tendermint2 JS / TS Client",
5
5
  "main": "./bin/index.js",
6
6
  "repository": {
@@ -30,10 +30,10 @@
30
30
  "@types/long": "^5.0.0",
31
31
  "@types/node": "^24.3.0",
32
32
  "@types/ws": "^8.5.11",
33
- "@typescript-eslint/eslint-plugin": "^8.39.1",
34
- "@typescript-eslint/parser": "^8.39.1",
35
- "@typescript-eslint/typescript-estree": "^8.39.1",
36
- "eslint": "^9.33.0",
33
+ "@typescript-eslint/eslint-plugin": "^8.42.0",
34
+ "@typescript-eslint/parser": "^8.42.0",
35
+ "@typescript-eslint/typescript-estree": "^8.42.0",
36
+ "eslint": "^9.35.0",
37
37
  "eslint-config-prettier": "^10.1.5",
38
38
  "eslint-plugin-prettier": "5.5.1",
39
39
  "globals": "^16.3.0",