@firmachain/firma-js 0.3.5 → 0.3.6-beta1

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.
@@ -0,0 +1,433 @@
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 (g && (g = 0, op[0] && (_ = 0)), _) 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 __values = (this && this.__values) || function(o) {
54
+ var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
55
+ if (m) return m.call(o);
56
+ if (o && typeof o.length === "number") return {
57
+ next: function () {
58
+ if (o && i >= o.length) o = void 0;
59
+ return { value: o && o[i++], done: !o };
60
+ }
61
+ };
62
+ throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
63
+ };
64
+ Object.defineProperty(exports, "__esModule", { value: true });
65
+ exports.StargateClient = exports.BroadcastTxError = exports.assertIsDeliverTxFailure = exports.assertIsDeliverTxSuccess = exports.isBroadcastTxSuccess = exports.isBroadcastTxFailure = exports.isDeliverTxSuccess = exports.isDeliverTxFailure = exports.TimeoutError = void 0;
66
+ /* eslint-disable @typescript-eslint/naming-convention */
67
+ var encoding_1 = require("@cosmjs/encoding");
68
+ var tendermint_rpc_1 = require("@cosmjs/tendermint-rpc");
69
+ var utils_1 = require("@cosmjs/utils");
70
+ var stargate_1 = require("@cosmjs/stargate");
71
+ var accounts_1 = require("./accounts");
72
+ var events_1 = require("./events");
73
+ var TimeoutError = /** @class */ (function (_super) {
74
+ __extends(TimeoutError, _super);
75
+ function TimeoutError(message, txId) {
76
+ var _this = _super.call(this, message) || this;
77
+ _this.txId = txId;
78
+ return _this;
79
+ }
80
+ return TimeoutError;
81
+ }(Error));
82
+ exports.TimeoutError = TimeoutError;
83
+ function isDeliverTxFailure(result) {
84
+ return !!result.code;
85
+ }
86
+ exports.isDeliverTxFailure = isDeliverTxFailure;
87
+ function isDeliverTxSuccess(result) {
88
+ return !isDeliverTxFailure(result);
89
+ }
90
+ exports.isDeliverTxSuccess = isDeliverTxSuccess;
91
+ function isBroadcastTxFailure(result) {
92
+ return !!result.code;
93
+ }
94
+ exports.isBroadcastTxFailure = isBroadcastTxFailure;
95
+ function isBroadcastTxSuccess(result) {
96
+ return !isBroadcastTxFailure(result);
97
+ }
98
+ exports.isBroadcastTxSuccess = isBroadcastTxSuccess;
99
+ /**
100
+ * Ensures the given result is a success. Throws a detailed error message otherwise.
101
+ */
102
+ function assertIsDeliverTxSuccess(result) {
103
+ if (isDeliverTxFailure(result)) {
104
+ throw new Error("Error when broadcasting tx ".concat(result.transactionHash, " at height ").concat(result.height, ". Code: ").concat(result.code, "; Check events for details."));
105
+ }
106
+ }
107
+ exports.assertIsDeliverTxSuccess = assertIsDeliverTxSuccess;
108
+ /**
109
+ * Ensures the given result is a failure. Throws a detailed error message otherwise.
110
+ */
111
+ function assertIsDeliverTxFailure(result) {
112
+ if (isDeliverTxSuccess(result)) {
113
+ throw new Error("Transaction ".concat(result.transactionHash, " did not fail at height ").concat(result.height, ". Code: ").concat(result.code, "; Check events for details."));
114
+ }
115
+ }
116
+ exports.assertIsDeliverTxFailure = assertIsDeliverTxFailure;
117
+ /**
118
+ * An error when broadcasting the transaction. This contains the CheckTx errors
119
+ * from the blockchain. Once a transaction is included in a block no BroadcastTxError
120
+ * is thrown, even if the execution fails (DeliverTx errors).
121
+ */
122
+ var BroadcastTxError = /** @class */ (function (_super) {
123
+ __extends(BroadcastTxError, _super);
124
+ function BroadcastTxError(code, codespace, log) {
125
+ var _this = _super.call(this, "Broadcasting transaction failed with code ".concat(code, " (codespace: ").concat(codespace, "). Log: ").concat(log)) || this;
126
+ _this.code = code;
127
+ _this.codespace = codespace;
128
+ _this.log = log;
129
+ return _this;
130
+ }
131
+ return BroadcastTxError;
132
+ }(Error));
133
+ exports.BroadcastTxError = BroadcastTxError;
134
+ /**
135
+ * Extracts message responses from transaction events.
136
+ * In Cosmos SDK v0.50+, message responses are embedded in events rather than separate data fields.
137
+ */
138
+ function extractMsgResponsesFromEvents(events) {
139
+ var e_1, _a, e_2, _b;
140
+ var msgResponses = [];
141
+ try {
142
+ for (var events_2 = __values(events), events_2_1 = events_2.next(); !events_2_1.done; events_2_1 = events_2.next()) {
143
+ var event_1 = events_2_1.value;
144
+ if (event_1.type === "message") {
145
+ try {
146
+ // Look for message response data in message events
147
+ for (var _c = (e_2 = void 0, __values(event_1.attributes)), _d = _c.next(); !_d.done; _d = _c.next()) {
148
+ var attr = _d.value;
149
+ if (attr.key === "module" || attr.key === "action") {
150
+ // Extract type information for message responses
151
+ var typeUrl = "/cosmos.".concat(attr.value);
152
+ msgResponses.push({
153
+ typeUrl: typeUrl,
154
+ value: new Uint8Array(), // In v0.50, detailed response data is in other events
155
+ });
156
+ }
157
+ }
158
+ }
159
+ catch (e_2_1) { e_2 = { error: e_2_1 }; }
160
+ finally {
161
+ try {
162
+ if (_d && !_d.done && (_b = _c.return)) _b.call(_c);
163
+ }
164
+ finally { if (e_2) throw e_2.error; }
165
+ }
166
+ }
167
+ }
168
+ }
169
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
170
+ finally {
171
+ try {
172
+ if (events_2_1 && !events_2_1.done && (_a = events_2.return)) _a.call(events_2);
173
+ }
174
+ finally { if (e_1) throw e_1.error; }
175
+ }
176
+ return msgResponses;
177
+ }
178
+ var StargateClient = /** @class */ (function () {
179
+ function StargateClient(cometClient, options) {
180
+ if (options === void 0) { options = {}; }
181
+ if (cometClient) {
182
+ this.cometClient = cometClient;
183
+ this.queryClient = stargate_1.QueryClient.withExtensions(cometClient, stargate_1.setupAuthExtension, stargate_1.setupBankExtension, stargate_1.setupStakingExtension, stargate_1.setupTxExtension);
184
+ }
185
+ var _a = options.accountParser, accountParser = _a === void 0 ? accounts_1.accountFromAny : _a;
186
+ this.accountParser = accountParser;
187
+ }
188
+ /**
189
+ * Creates an instance by connecting to the given CometBFT RPC endpoint.
190
+ *
191
+ * This uses auto-detection to decide between a CometBFT 0.38, Tendermint 0.37 and 0.34 client.
192
+ * To set the Comet client explicitly, use `create`.
193
+ */
194
+ StargateClient.connect = function (endpoint, options) {
195
+ if (options === void 0) { options = {}; }
196
+ return __awaiter(this, void 0, void 0, function () {
197
+ var cometClient;
198
+ return __generator(this, function (_a) {
199
+ switch (_a.label) {
200
+ case 0: return [4 /*yield*/, (0, tendermint_rpc_1.connectComet)(endpoint)];
201
+ case 1:
202
+ cometClient = _a.sent();
203
+ return [2 /*return*/, StargateClient.create(cometClient, options)];
204
+ }
205
+ });
206
+ });
207
+ };
208
+ /**
209
+ * Creates an instance from a manually created Comet client.
210
+ * Use this to use `Comet38Client` or `Tendermint37Client` instead of `Tendermint34Client`.
211
+ */
212
+ StargateClient.create = function (cometClient, options) {
213
+ if (options === void 0) { options = {}; }
214
+ return __awaiter(this, void 0, void 0, function () {
215
+ return __generator(this, function (_a) {
216
+ return [2 /*return*/, new StargateClient(cometClient, options)];
217
+ });
218
+ });
219
+ };
220
+ StargateClient.prototype.getCometClient = function () {
221
+ return this.cometClient;
222
+ };
223
+ StargateClient.prototype.forceGetCometClient = function () {
224
+ if (!this.cometClient) {
225
+ throw new Error("Comet client not available. You cannot use online functionality in offline mode.");
226
+ }
227
+ return this.cometClient;
228
+ };
229
+ StargateClient.prototype.getQueryClient = function () {
230
+ return this.queryClient;
231
+ };
232
+ StargateClient.prototype.forceGetQueryClient = function () {
233
+ if (!this.queryClient) {
234
+ throw new Error("Query client not available. You cannot use online functionality in offline mode.");
235
+ }
236
+ return this.queryClient;
237
+ };
238
+ StargateClient.prototype.getChainId = function () {
239
+ return __awaiter(this, void 0, void 0, function () {
240
+ var response, chainId;
241
+ return __generator(this, function (_a) {
242
+ switch (_a.label) {
243
+ case 0:
244
+ if (!!this.chainId) return [3 /*break*/, 2];
245
+ return [4 /*yield*/, this.forceGetCometClient().status()];
246
+ case 1:
247
+ response = _a.sent();
248
+ chainId = response.nodeInfo.network;
249
+ if (!chainId)
250
+ throw new Error("Chain ID must not be empty");
251
+ this.chainId = chainId;
252
+ _a.label = 2;
253
+ case 2: return [2 /*return*/, this.chainId];
254
+ }
255
+ });
256
+ });
257
+ };
258
+ StargateClient.prototype.getHeight = function () {
259
+ return __awaiter(this, void 0, void 0, function () {
260
+ var status;
261
+ return __generator(this, function (_a) {
262
+ switch (_a.label) {
263
+ case 0: return [4 /*yield*/, this.forceGetCometClient().status()];
264
+ case 1:
265
+ status = _a.sent();
266
+ return [2 /*return*/, status.syncInfo.latestBlockHeight];
267
+ }
268
+ });
269
+ });
270
+ };
271
+ StargateClient.prototype.getAccount = function (searchAddress) {
272
+ return __awaiter(this, void 0, void 0, function () {
273
+ var account, error_1;
274
+ return __generator(this, function (_a) {
275
+ switch (_a.label) {
276
+ case 0:
277
+ _a.trys.push([0, 2, , 3]);
278
+ return [4 /*yield*/, this.forceGetQueryClient().auth.account(searchAddress)];
279
+ case 1:
280
+ account = _a.sent();
281
+ return [2 /*return*/, account ? this.accountParser(account) : null];
282
+ case 2:
283
+ error_1 = _a.sent();
284
+ if (/rpc error: code = NotFound/i.test(error_1.toString())) {
285
+ return [2 /*return*/, null];
286
+ }
287
+ throw error_1;
288
+ case 3: return [2 /*return*/];
289
+ }
290
+ });
291
+ });
292
+ };
293
+ StargateClient.prototype.getSequence = function (address) {
294
+ return __awaiter(this, void 0, void 0, function () {
295
+ var account;
296
+ return __generator(this, function (_a) {
297
+ switch (_a.label) {
298
+ case 0: return [4 /*yield*/, this.getAccount(address)];
299
+ case 1:
300
+ account = _a.sent();
301
+ if (!account) {
302
+ throw new Error("Account '".concat(address, "' does not exist on chain. Send some tokens there before trying to query sequence."));
303
+ }
304
+ return [2 /*return*/, {
305
+ accountNumber: account.accountNumber,
306
+ sequence: account.sequence,
307
+ }];
308
+ }
309
+ });
310
+ });
311
+ };
312
+ StargateClient.prototype.getTx = function (id) {
313
+ var _a;
314
+ return __awaiter(this, void 0, void 0, function () {
315
+ var results;
316
+ return __generator(this, function (_b) {
317
+ switch (_b.label) {
318
+ case 0: return [4 /*yield*/, this.txsQuery("tx.hash='".concat(id, "'"))];
319
+ case 1:
320
+ results = _b.sent();
321
+ return [2 /*return*/, (_a = results[0]) !== null && _a !== void 0 ? _a : null];
322
+ }
323
+ });
324
+ });
325
+ };
326
+ StargateClient.prototype.disconnect = function () {
327
+ if (this.cometClient)
328
+ this.cometClient.disconnect();
329
+ };
330
+ /**
331
+ * Broadcasts a signed transaction to the network and monitors its inclusion in a block.
332
+ *
333
+ * If broadcasting is rejected by the node for some reason (e.g. because of a CheckTx failure),
334
+ * an error is thrown.
335
+ *
336
+ * If the transaction is not included in a block before the provided timeout, this errors with a `TimeoutError`.
337
+ *
338
+ * If the transaction is included in a block, a `DeliverTxResponse` is returned. The caller then
339
+ * usually needs to check for execution success or failure.
340
+ */
341
+ StargateClient.prototype.broadcastTx = function (tx, timeoutMs, pollIntervalMs) {
342
+ var _a;
343
+ if (timeoutMs === void 0) { timeoutMs = 60000; }
344
+ if (pollIntervalMs === void 0) { pollIntervalMs = 3000; }
345
+ return __awaiter(this, void 0, void 0, function () {
346
+ var timedOut, txPollTimeout, pollForTx, broadcasted, transactionId;
347
+ var _this = this;
348
+ return __generator(this, function (_b) {
349
+ switch (_b.label) {
350
+ case 0:
351
+ timedOut = false;
352
+ txPollTimeout = setTimeout(function () {
353
+ timedOut = true;
354
+ }, timeoutMs);
355
+ pollForTx = function (txId) { return __awaiter(_this, void 0, void 0, function () {
356
+ var result;
357
+ return __generator(this, function (_a) {
358
+ switch (_a.label) {
359
+ case 0:
360
+ if (timedOut) {
361
+ throw new TimeoutError("Transaction with ID ".concat(txId, " was submitted but was not yet found on the chain. You might want to check later. There was a wait of ").concat(timeoutMs / 1000, " seconds."), txId);
362
+ }
363
+ return [4 /*yield*/, (0, utils_1.sleep)(pollIntervalMs)];
364
+ case 1:
365
+ _a.sent();
366
+ return [4 /*yield*/, this.getTx(txId)];
367
+ case 2:
368
+ result = _a.sent();
369
+ return [2 /*return*/, result
370
+ ? {
371
+ code: result.code,
372
+ height: result.height,
373
+ txIndex: result.txIndex,
374
+ events: result.events,
375
+ transactionHash: txId,
376
+ msgResponses: result.msgResponses,
377
+ gasUsed: result.gasUsed,
378
+ gasWanted: result.gasWanted,
379
+ }
380
+ : pollForTx(txId)];
381
+ }
382
+ });
383
+ }); };
384
+ return [4 /*yield*/, this.forceGetCometClient().broadcastTxSync({ tx: tx })];
385
+ case 1:
386
+ broadcasted = _b.sent();
387
+ if (broadcasted.code) {
388
+ return [2 /*return*/, Promise.reject(new BroadcastTxError(broadcasted.code, (_a = broadcasted.codespace) !== null && _a !== void 0 ? _a : "", broadcasted.log))];
389
+ }
390
+ transactionId = (0, encoding_1.toHex)(broadcasted.hash).toUpperCase();
391
+ return [2 /*return*/, new Promise(function (resolve, reject) {
392
+ return pollForTx(transactionId).then(function (value) {
393
+ clearTimeout(txPollTimeout);
394
+ resolve(value);
395
+ }, function (error) {
396
+ clearTimeout(txPollTimeout);
397
+ reject(error);
398
+ });
399
+ })];
400
+ }
401
+ });
402
+ });
403
+ };
404
+ StargateClient.prototype.txsQuery = function (query) {
405
+ return __awaiter(this, void 0, void 0, function () {
406
+ var results;
407
+ return __generator(this, function (_a) {
408
+ switch (_a.label) {
409
+ case 0: return [4 /*yield*/, this.forceGetCometClient().txSearchAll({ query: query })];
410
+ case 1:
411
+ results = _a.sent();
412
+ return [2 /*return*/, results.txs.map(function (tx) {
413
+ var events = tx.result.events.map(events_1.fromTendermintEvent);
414
+ var msgResponses = extractMsgResponsesFromEvents(events);
415
+ return {
416
+ height: tx.height,
417
+ txIndex: tx.index,
418
+ hash: (0, encoding_1.toHex)(tx.hash).toUpperCase(),
419
+ code: tx.result.code,
420
+ events: events,
421
+ tx: tx.tx,
422
+ msgResponses: msgResponses,
423
+ gasUsed: tx.result.gasUsed,
424
+ gasWanted: tx.result.gasWanted,
425
+ };
426
+ })];
427
+ }
428
+ });
429
+ });
430
+ };
431
+ return StargateClient;
432
+ }());
433
+ exports.StargateClient = StargateClient;
@@ -40,7 +40,7 @@ var chai_1 = require("chai");
40
40
  var FirmaSDK_1 = require("../sdk/FirmaSDK");
41
41
  var FirmaUtil_1 = require("../sdk/FirmaUtil");
42
42
  var config_test_1 = require("./config_test");
43
- var encoding_1 = require("@cosmjs/encoding");
43
+ var bank_1 = require("../sdk/firmachain/bank");
44
44
  describe('[27. protobuf arbitrary sign]', function () {
45
45
  var firma;
46
46
  var aliceWallet;
@@ -71,59 +71,88 @@ describe('[27. protobuf arbitrary sign]', function () {
71
71
  });
72
72
  });
73
73
  it('protobuf arbitrary sign & verify basic test', function () { return __awaiter(void 0, void 0, void 0, function () {
74
- var testMsg, testBytes, result, isValid;
74
+ var testMsg, signatureResult, isMatch;
75
75
  return __generator(this, function (_a) {
76
76
  switch (_a.label) {
77
77
  case 0:
78
78
  testMsg = "be14202e-46dc-4d38-924c-65db209ea2fb";
79
- testBytes = (0, encoding_1.toUtf8)(testMsg);
80
- return [4 /*yield*/, FirmaUtil_1.FirmaUtil.protobufArbitrarySign(aliceWallet, aliceAddress, testBytes)];
79
+ return [4 /*yield*/, FirmaUtil_1.FirmaUtil.experimentalAdr36Sign(aliceWallet, testMsg)];
81
80
  case 1:
82
- result = _a.sent();
83
- return [4 /*yield*/, FirmaUtil_1.FirmaUtil.protobufArbitraryVerify(result, testBytes)];
81
+ signatureResult = _a.sent();
82
+ return [4 /*yield*/, FirmaUtil_1.FirmaUtil.experimentalAdr36Verify(signatureResult, testMsg)];
84
83
  case 2:
85
- isValid = _a.sent();
86
- (0, chai_1.expect)(isValid).to.be.equal(true);
84
+ isMatch = _a.sent();
85
+ (0, chai_1.expect)(isMatch).to.be.equal(true);
87
86
  return [2 /*return*/];
88
87
  }
89
88
  });
90
89
  }); });
91
- it('protobuf arbitrary sign - tampered message should fail', function () { return __awaiter(void 0, void 0, void 0, function () {
92
- var testMsg, testBytes, result, tamperedBytes, isValid;
90
+ it('direct sign & verify basic test', function () { return __awaiter(void 0, void 0, void 0, function () {
91
+ var amountFCT, alicePubkey, sendAmount, msgSend, stringSignDoc, signDoc, commonTxClient, extTxRaw, valid;
93
92
  return __generator(this, function (_a) {
94
93
  switch (_a.label) {
95
94
  case 0:
96
- testMsg = "original-message";
97
- testBytes = (0, encoding_1.toUtf8)(testMsg);
98
- return [4 /*yield*/, FirmaUtil_1.FirmaUtil.protobufArbitrarySign(aliceWallet, aliceAddress, testBytes)];
95
+ amountFCT = 9;
96
+ return [4 /*yield*/, aliceWallet.getPubKey()];
99
97
  case 1:
100
- result = _a.sent();
101
- tamperedBytes = (0, encoding_1.toUtf8)("modified-message");
102
- return [4 /*yield*/, FirmaUtil_1.FirmaUtil.protobufArbitraryVerify(result, tamperedBytes)];
98
+ alicePubkey = _a.sent();
99
+ sendAmount = { denom: firma.Config.denom, amount: FirmaUtil_1.FirmaUtil.getUFCTStringFromFCT(amountFCT) };
100
+ msgSend = bank_1.BankTxClient.msgSend({
101
+ fromAddress: aliceAddress,
102
+ toAddress: bobAddress,
103
+ amount: [sendAmount]
104
+ });
105
+ return [4 /*yield*/, FirmaUtil_1.FirmaUtil.makeSignDocWithStringify(aliceAddress, alicePubkey, [msgSend])];
103
106
  case 2:
104
- isValid = _a.sent();
105
- (0, chai_1.expect)(isValid).to.be.equal(false);
107
+ stringSignDoc = _a.sent();
108
+ signDoc = FirmaUtil_1.FirmaUtil.parseSignDocValues(stringSignDoc);
109
+ commonTxClient = FirmaUtil_1.FirmaUtil.getCommonTxClient(aliceWallet);
110
+ return [4 /*yield*/, commonTxClient.signDirectForSignDoc(aliceAddress, signDoc)];
111
+ case 3:
112
+ extTxRaw = _a.sent();
113
+ return [4 /*yield*/, FirmaUtil_1.FirmaUtil.verifyDirectSignature(aliceAddress, extTxRaw.signature, signDoc)];
114
+ case 4:
115
+ valid = _a.sent();
116
+ (0, chai_1.expect)(valid).to.be.equal(true);
106
117
  return [2 /*return*/];
107
118
  }
108
119
  });
109
120
  }); });
110
- it('protobuf arbitrary sign - tampered signature should fail', function () { return __awaiter(void 0, void 0, void 0, function () {
111
- var testMsg, testBytes, result, isValid;
121
+ it('direct sign & verify & send basic test', function () { return __awaiter(void 0, void 0, void 0, function () {
122
+ var amountFCT, alicePubkey, sendAmount, msgSend, signDoc, stringSignDoc, newSignDoc, commonTxClient, extTxRaw, valid, result;
112
123
  return __generator(this, function (_a) {
113
124
  switch (_a.label) {
114
125
  case 0:
115
- testMsg = "integrity-check";
116
- testBytes = (0, encoding_1.toUtf8)(testMsg);
117
- return [4 /*yield*/, FirmaUtil_1.FirmaUtil.protobufArbitrarySign(aliceWallet, aliceAddress, testBytes)];
126
+ amountFCT = 9;
127
+ return [4 /*yield*/, aliceWallet.getPubKey()];
118
128
  case 1:
119
- result = _a.sent();
120
- // modify signature base64 (simulate corruption) - change first character
121
- // console.log("Original signature:", result.signature);
122
- result.signature = "X" + result.signature.substring(1);
123
- return [4 /*yield*/, FirmaUtil_1.FirmaUtil.protobufArbitraryVerify(result, testBytes)];
129
+ alicePubkey = _a.sent();
130
+ sendAmount = { denom: firma.Config.denom, amount: FirmaUtil_1.FirmaUtil.getUFCTStringFromFCT(amountFCT) };
131
+ msgSend = bank_1.BankTxClient.msgSend({
132
+ fromAddress: aliceAddress,
133
+ toAddress: bobAddress,
134
+ amount: [sendAmount]
135
+ });
136
+ return [4 /*yield*/, FirmaUtil_1.FirmaUtil.makeSignDoc(aliceAddress, alicePubkey, [msgSend])];
124
137
  case 2:
125
- isValid = _a.sent();
126
- (0, chai_1.expect)(isValid).to.be.equal(false);
138
+ signDoc = _a.sent();
139
+ stringSignDoc = FirmaUtil_1.FirmaUtil.stringifySignDocValues(signDoc);
140
+ newSignDoc = FirmaUtil_1.FirmaUtil.parseSignDocValues(stringSignDoc);
141
+ commonTxClient = FirmaUtil_1.FirmaUtil.getCommonTxClient(aliceWallet);
142
+ return [4 /*yield*/, commonTxClient.signDirectForSignDoc(aliceAddress, newSignDoc)];
143
+ case 3:
144
+ extTxRaw = _a.sent();
145
+ return [4 /*yield*/, FirmaUtil_1.FirmaUtil.verifyDirectSignature(aliceAddress, extTxRaw.signature, newSignDoc)];
146
+ case 4:
147
+ valid = _a.sent();
148
+ if (!valid) return [3 /*break*/, 6];
149
+ return [4 /*yield*/, commonTxClient.broadcast(extTxRaw.txRaw)];
150
+ case 5:
151
+ result = _a.sent();
152
+ (0, chai_1.expect)(result.code).to.be.equal(0);
153
+ _a.label = 6;
154
+ case 6:
155
+ (0, chai_1.expect)(valid).to.be.equal(true);
127
156
  return [2 /*return*/];
128
157
  }
129
158
  });
@@ -1,7 +1,7 @@
1
1
  import { FirmaConfig } from '../sdk/FirmaConfig';
2
2
  export declare let TestChainConfig: FirmaConfig;
3
- export declare const validatorMnemonic = "angry water bunker where iron absurd cruise deliver clutch unique creek pyramid arch express flush pill lens concert absent enemy boring mom nuclear rose";
4
- export declare const aliceMnemonic = "immune flavor record sphere foam planet faint grid disorder flag minute eternal beef sea camp surge extra scorpion pistol plastic happy siren juice found";
3
+ export declare const validatorMnemonic = "stadium lonely midnight okay meat rib awesome wealth phone leisure turn prosper notable label fruit define little also father silver half drill bargain antique";
4
+ export declare const aliceMnemonic = "uncle banana theme relax oak prosper volcano glad industry bicycle tower thrive jelly curious luggage frame that defy reason jewel figure begin nice moon";
5
5
  export declare const bobMnemonic = "innocent enforce visit tilt job kitten actual glory flash feed wonder license rubber outer drum sun fuel relax roof universe enrich pulse fine grid";
6
6
  export declare const feeMnemonic = "long shallow crumble clown truth book oval render seed canal buffalo assist sadness elbow afraid catalog brother trade food subject must luggage bread neither";
7
7
  export declare const firmaFeeMnemonic = "arrest dynamic typical lunch original glare truth narrow stairs clip canyon space alley chat drive sudden music bubble time mesh color office minor draft";
@@ -1,6 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.signerMnemonic4 = exports.signerMnemonic3 = exports.signerMnemonic2 = exports.signerMnemonic1 = exports.firmaFeeMnemonic = exports.feeMnemonic = exports.bobMnemonic = exports.aliceMnemonic = exports.validatorMnemonic = exports.TestChainConfig = void 0;
4
+ var FirmaConfig_1 = require("../sdk/FirmaConfig");
5
+ var config = FirmaConfig_1.FirmaConfig.TestNetConfig;
6
+ config.isShowLog = false;
4
7
  // export let TestChainConfig: FirmaConfig = FirmaConfig.TestNetConfig;
5
8
  exports.TestChainConfig = {
6
9
  chainID: "roma-1",
@@ -16,24 +19,38 @@ exports.TestChainConfig = {
16
19
  defaultGas: 200000,
17
20
  isShowLog: false,
18
21
  };
19
- exports.validatorMnemonic = "angry water bunker where iron absurd cruise deliver clutch unique creek pyramid arch express flush pill lens concert absent enemy boring mom nuclear rose";
20
22
  // DEVNET
21
- exports.aliceMnemonic = "immune flavor record sphere foam planet faint grid disorder flag minute eternal beef sea camp surge extra scorpion pistol plastic happy siren juice found";
23
+ // export const validatorMnemonic = "rebel engine situate catalog blood strong satisfy aerobic cupboard again vivid twice flag work taxi heart fruit island ribbon hungry cheap ordinary horse foam";
24
+ // VALIDATOR 2
25
+ exports.validatorMnemonic = "stadium lonely midnight okay meat rib awesome wealth phone leisure turn prosper notable label fruit define little also father silver half drill bargain antique";
26
+ exports.aliceMnemonic = "uncle banana theme relax oak prosper volcano glad industry bicycle tower thrive jelly curious luggage frame that defy reason jewel figure begin nice moon";
27
+ exports.bobMnemonic = "innocent enforce visit tilt job kitten actual glory flash feed wonder license rubber outer drum sun fuel relax roof universe enrich pulse fine grid";
28
+ // TESTNET
29
+ // export const validatorMnemonic = "owner pottery smile evolve pig base lady dismiss badge purchase divide royal medal buffalo miss carbon kiwi gate draft mouse yard reunion thank wage";
30
+ // export const validatorMnemonic = "main shallow liberty desk super palm remind throw track legal warrior client garbage type insect first token keen subway pony curtain pitch yellow arrive";
31
+ // export const aliceMnemonic = "harvest galaxy sniff include record undo width oven tired sad month text museum curious firm mountain flash assault oval sand ribbon blouse consider lens";
32
+ // export const bobMnemonic = "certain bean eager measure crawl cliff innocent practice gas ladder board aspect fish link sweet raccoon staff long crumble skin special width click plastic";
33
+ // testnet인데 임시로 바꿈
34
+ // export const bobMnemonic = "harvest galaxy sniff include record undo width oven tired sad month text museum curious firm mountain flash assault oval sand ribbon blouse consider lens";
35
+ // export const aliceMnemonic = "certain bean eager measure crawl cliff innocent practice gas ladder board aspect fish link sweet raccoon staff long crumble skin special width click plastic";
36
+ // DEVNET validator 4
37
+ // export const validatorMnemonic = "ladder damage art company shield glance cushion float need layer rare toast intact grief wet point write season correct access mix bomb accident estate";
38
+ // DEVNET validator 3
39
+ // export const validatorMnemonic = "rebel engine situate catalog blood strong satisfy aerobic cupboard again vivid twice flag work taxi heart fruit island ribbon hungry cheap ordinary horse foam";
40
+ // DEVNET
41
+ // export const aliceMnemonic = "immune flavor record sphere foam planet faint grid disorder flag minute eternal beef sea camp surge extra scorpion pistol plastic happy siren juice found";
22
42
  // TESTNET
23
43
  // export const aliceMnemonic = "harvest galaxy sniff include record undo width oven tired sad month text museum curious firm mountain flash assault oval sand ribbon blouse consider lens";
24
44
  // VALIDATOR
25
45
  // export const aliceMnemonic = "clump erupt type lucky mask pig soup runway wrestle suspect element involve stamp civil auction resource blame same journey start unaware crush ten draw";
26
46
  // export const aliceMnemonic = "owner pottery smile evolve pig base lady dismiss badge purchase divide royal medal buffalo miss carbon kiwi gate draft mouse yard reunion thank wage";
27
47
  // export const aliceMnemonic = "main shallow liberty desk super palm remind throw track legal warrior client garbage type insect first token keen subway pony curtain pitch yellow arrive";
28
- // voting test
29
- // export const aliceMnemonic = "long shallow crumble clown truth book oval render seed canal buffalo assist sadness elbow afraid catalog brother trade food subject must luggage bread neither";
30
48
  // export const aliceMnemonic = "clump erupt type lucky mask pig soup runway wrestle suspect element involve stamp civil auction resource blame same journey start unaware crush ten draw";
31
49
  // export const aliceMnemonic = "angry water bunker where iron absurd cruise deliver clutch unique creek pyramid arch express flush pill lens concert absent enemy boring mom nuclear rose";
32
50
  // export const aliceMnemonic = "stadium lonely midnight okay meat rib awesome wealth phone leisure turn prosper notable label fruit define little also father silver half drill bargain antique";
33
51
  // export const aliceMnemonic = "uncle banana theme relax oak prosper volcano glad industry bicycle tower thrive jelly curious luggage frame that defy reason jewel figure begin nice moon";
34
52
  // export const aliceMnemonic = "rebel engine situate catalog blood strong satisfy aerobic cupboard again vivid twice flag work taxi heart fruit island ribbon hungry cheap ordinary horse foam";
35
53
  // export const aliceMnemonic = "ladder damage art company shield glance cushion float need layer rare toast intact grief wet point write season correct access mix bomb accident estate";
36
- exports.bobMnemonic = "innocent enforce visit tilt job kitten actual glory flash feed wonder license rubber outer drum sun fuel relax roof universe enrich pulse fine grid";
37
54
  exports.feeMnemonic = "long shallow crumble clown truth book oval render seed canal buffalo assist sadness elbow afraid catalog brother trade food subject must luggage bread neither";
38
55
  exports.firmaFeeMnemonic = "arrest dynamic typical lunch original glare truth narrow stairs clip canyon space alley chat drive sudden music bubble time mesh color office minor draft";
39
56
  // export const firmaFeeMnemonic = "child material talent property foot sign talent congress cargo pistol suspect screen leader owner type style patch amused stable flame sure fluid april acoustic";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@firmachain/firma-js",
3
- "version": "0.3.5",
3
+ "version": "0.3.6-beta1",
4
4
  "description": "The Official FirmaChain Javascript SDK written in Typescript",
5
5
  "main": "dist/index.js",
6
6
  "typings": "dist/index.d.ts",