@firmachain/firma-js 0.2.36 → 0.2.39

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.
@@ -14,8 +14,8 @@ export declare class FirmaAuthzService {
14
14
  private getSignedTxExecuteAllowance;
15
15
  getGasEstimationGrantSendAuthorization(wallet: FirmaWalletService, granteeAddress: string, expirationDate: Date, maxTokens: number, txMisc?: TxMisc): Promise<number>;
16
16
  grantSendAuthorization(wallet: FirmaWalletService, granteeAddress: string, expirationDate: Date, maxTokens: number, txMisc?: TxMisc): Promise<BroadcastTxResponse>;
17
- getGasEstimationGrantStakeAuthorization(wallet: FirmaWalletService, granteeAddress: string, validatorAddress: string, type: AuthorizationType, expirationDate: Date, maxTokens?: number, txMisc?: TxMisc): Promise<number>;
18
- grantStakeAuthorization(wallet: FirmaWalletService, granteeAddress: string, validatorAddress: string, type: AuthorizationType, expirationDate: Date, maxTokens?: number, txMisc?: TxMisc): Promise<BroadcastTxResponse>;
17
+ getGasEstimationGrantStakeAuthorization(wallet: FirmaWalletService, granteeAddress: string, validatorAddressList: string[], type: AuthorizationType, expirationDate: Date, maxTokens?: number, txMisc?: TxMisc): Promise<number>;
18
+ grantStakeAuthorization(wallet: FirmaWalletService, granteeAddress: string, validatorAddressList: string[], type: AuthorizationType, expirationDate: Date, maxTokens?: number, txMisc?: TxMisc): Promise<BroadcastTxResponse>;
19
19
  getGasEstimationGrantGenericAuthorization(wallet: FirmaWalletService, granteeAddress: string, msg: string, expirationDate: Date, txMisc?: TxMisc): Promise<number>;
20
20
  grantGenericAuthorization(wallet: FirmaWalletService, granteeAddress: string, msg: string, expirationDate: Date, txMisc?: TxMisc): Promise<BroadcastTxResponse>;
21
21
  getGasEstimationRevokeGenericAuthorization(wallet: FirmaWalletService, granteeAddress: string, msgType: string, txMisc?: TxMisc): Promise<number>;
@@ -84,7 +84,7 @@ var FirmaAuthzService = /** @class */ (function () {
84
84
  });
85
85
  });
86
86
  };
87
- FirmaAuthzService.prototype.getSignedTxGrantStakeAutorization = function (wallet, granteeAddress, validatorAddress, type, maxTokens, expirationDate, txMisc) {
87
+ FirmaAuthzService.prototype.getSignedTxGrantStakeAutorization = function (wallet, granteeAddress, validatorAddressList, type, maxTokens, expirationDate, txMisc) {
88
88
  if (txMisc === void 0) { txMisc = FirmaUtil_1.DefaultTxMisc; }
89
89
  return __awaiter(this, void 0, void 0, function () {
90
90
  var address, authorization, timestamp, message, authzTxClient, error_2;
@@ -98,7 +98,7 @@ var FirmaAuthzService = /** @class */ (function () {
98
98
  authorization = any_1.Any.fromPartial({
99
99
  typeUrl: "/cosmos.staking.v1beta1.StakeAuthorization",
100
100
  value: Uint8Array.from(AuthzTxTypes_1.StakeAuthorization.encode(AuthzTxTypes_1.StakeAuthorization.fromPartial({
101
- allowList: { address: [validatorAddress] },
101
+ allowList: { address: validatorAddressList },
102
102
  maxTokens: (maxTokens === "0") ? undefined : { denom: this.config.denom, amount: maxTokens },
103
103
  authorizationType: type
104
104
  })).finish()),
@@ -263,7 +263,7 @@ var FirmaAuthzService = /** @class */ (function () {
263
263
  });
264
264
  });
265
265
  };
266
- FirmaAuthzService.prototype.getGasEstimationGrantStakeAuthorization = function (wallet, granteeAddress, validatorAddress, type, expirationDate, maxTokens, txMisc) {
266
+ FirmaAuthzService.prototype.getGasEstimationGrantStakeAuthorization = function (wallet, granteeAddress, validatorAddressList, type, expirationDate, maxTokens, txMisc) {
267
267
  if (maxTokens === void 0) { maxTokens = 0; }
268
268
  if (txMisc === void 0) { txMisc = FirmaUtil_1.DefaultTxMisc; }
269
269
  return __awaiter(this, void 0, void 0, function () {
@@ -272,7 +272,7 @@ var FirmaAuthzService = /** @class */ (function () {
272
272
  switch (_a.label) {
273
273
  case 0:
274
274
  _a.trys.push([0, 3, , 4]);
275
- return [4 /*yield*/, this.getSignedTxGrantStakeAutorization(wallet, granteeAddress, validatorAddress, type, FirmaUtil_1.FirmaUtil.getUFCTStringFromFCT(maxTokens), expirationDate, txMisc)];
275
+ return [4 /*yield*/, this.getSignedTxGrantStakeAutorization(wallet, granteeAddress, validatorAddressList, type, FirmaUtil_1.FirmaUtil.getUFCTStringFromFCT(maxTokens), expirationDate, txMisc)];
276
276
  case 1:
277
277
  txRaw = _a.sent();
278
278
  return [4 /*yield*/, FirmaUtil_1.FirmaUtil.estimateGas(txRaw)];
@@ -286,7 +286,7 @@ var FirmaAuthzService = /** @class */ (function () {
286
286
  });
287
287
  });
288
288
  };
289
- FirmaAuthzService.prototype.grantStakeAuthorization = function (wallet, granteeAddress, validatorAddress, type, expirationDate, maxTokens, txMisc) {
289
+ FirmaAuthzService.prototype.grantStakeAuthorization = function (wallet, granteeAddress, validatorAddressList, type, expirationDate, maxTokens, txMisc) {
290
290
  if (maxTokens === void 0) { maxTokens = 0; }
291
291
  if (txMisc === void 0) { txMisc = FirmaUtil_1.DefaultTxMisc; }
292
292
  return __awaiter(this, void 0, void 0, function () {
@@ -295,7 +295,7 @@ var FirmaAuthzService = /** @class */ (function () {
295
295
  switch (_a.label) {
296
296
  case 0:
297
297
  _a.trys.push([0, 3, , 4]);
298
- return [4 /*yield*/, this.getSignedTxGrantStakeAutorization(wallet, granteeAddress, validatorAddress, type, FirmaUtil_1.FirmaUtil.getUFCTStringFromFCT(maxTokens), expirationDate, txMisc)];
298
+ return [4 /*yield*/, this.getSignedTxGrantStakeAutorization(wallet, granteeAddress, validatorAddressList, type, FirmaUtil_1.FirmaUtil.getUFCTStringFromFCT(maxTokens), expirationDate, txMisc)];
299
299
  case 1:
300
300
  txRaw = _a.sent();
301
301
  authzTxClient = new authz_1.AuthzTxClient(wallet, this.config.rpcAddress);
@@ -1,12 +1,10 @@
1
1
  import { FirmaConfig } from "./FirmaConfig";
2
2
  export declare class IpfsService {
3
3
  private readonly config;
4
- private ipfsNodeClient;
5
- private readonly protocol;
6
4
  constructor(config: FirmaConfig);
5
+ private getBasePostUrl;
7
6
  addJson(jsonData: string): Promise<string>;
8
7
  addBuffer(buffer: ArrayBuffer): Promise<string>;
9
8
  addFile(fileUrl: string): Promise<string>;
10
- getFile(hash: string): Promise<string>;
11
9
  getURLFromHash(hash: string): string;
12
10
  }
@@ -35,49 +35,40 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
35
35
  if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
36
  }
37
37
  };
38
- var __asyncValues = (this && this.__asyncValues) || function (o) {
39
- if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
40
- var m = o[Symbol.asyncIterator], i;
41
- return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
42
- function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
43
- function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
44
- };
45
38
  var __importDefault = (this && this.__importDefault) || function (mod) {
46
39
  return (mod && mod.__esModule) ? mod : { "default": mod };
47
40
  };
48
41
  Object.defineProperty(exports, "__esModule", { value: true });
49
42
  exports.IpfsService = void 0;
50
- var ipfs_http_client_1 = require("ipfs-http-client");
51
43
  var fs_1 = __importDefault(require("fs"));
52
44
  var FirmaUtil_1 = require("./FirmaUtil");
45
+ var axios_1 = __importDefault(require("axios"));
53
46
  var IpfsService = /** @class */ (function () {
54
47
  function IpfsService(config) {
55
48
  this.config = config;
56
- if (config.ipfsNodeAddress.includes("https://")) {
57
- this.protocol = "https";
58
- }
59
- else if (config.ipfsNodeAddress.includes("http://")) {
60
- this.protocol = "http";
61
- }
62
- else {
63
- this.protocol = "https";
64
- }
65
- var address = config.ipfsNodeAddress;
66
- address = address.replace("https://", "");
67
- address = address.replace("http://", "");
68
- this.ipfsNodeClient = (0, ipfs_http_client_1.create)({ host: address, port: config.ipfsNodePort, protocol: this.protocol });
69
49
  }
50
+ IpfsService.prototype.getBasePostUrl = function () {
51
+ return this.config.ipfsNodeAddress + ":" + this.config.ipfsNodePort + "/api/v0/add";
52
+ };
70
53
  IpfsService.prototype.addJson = function (jsonData) {
71
54
  return __awaiter(this, void 0, void 0, function () {
72
- var result, error_1;
55
+ var FormData_1, bodyData, response, error_1;
73
56
  return __generator(this, function (_a) {
74
57
  switch (_a.label) {
75
58
  case 0:
76
59
  _a.trys.push([0, 2, , 3]);
77
- return [4 /*yield*/, this.ipfsNodeClient.add(jsonData)];
60
+ FormData_1 = require('form-data');
61
+ bodyData = new FormData_1();
62
+ bodyData.append('json', jsonData);
63
+ return [4 /*yield*/, axios_1.default.request({
64
+ url: this.getBasePostUrl(),
65
+ method: 'POST',
66
+ headers: bodyData.getHeaders(),
67
+ data: bodyData
68
+ })];
78
69
  case 1:
79
- result = _a.sent();
80
- return [2 /*return*/, result.cid.toString()];
70
+ response = _a.sent();
71
+ return [2 /*return*/, response.data.Hash];
81
72
  case 2:
82
73
  error_1 = _a.sent();
83
74
  FirmaUtil_1.FirmaUtil.printLog(error_1);
@@ -89,15 +80,23 @@ var IpfsService = /** @class */ (function () {
89
80
  };
90
81
  IpfsService.prototype.addBuffer = function (buffer) {
91
82
  return __awaiter(this, void 0, void 0, function () {
92
- var result, error_2;
83
+ var FormData_2, bodyData, response, error_2;
93
84
  return __generator(this, function (_a) {
94
85
  switch (_a.label) {
95
86
  case 0:
96
87
  _a.trys.push([0, 2, , 3]);
97
- return [4 /*yield*/, this.ipfsNodeClient.add(buffer)];
88
+ FormData_2 = require('form-data');
89
+ bodyData = new FormData_2();
90
+ bodyData.append('buffer', Buffer.from(buffer));
91
+ return [4 /*yield*/, axios_1.default.request({
92
+ url: this.getBasePostUrl(),
93
+ method: 'POST',
94
+ headers: bodyData.getHeaders(),
95
+ data: bodyData
96
+ })];
98
97
  case 1:
99
- result = _a.sent();
100
- return [2 /*return*/, result.cid.toString()];
98
+ response = _a.sent();
99
+ return [2 /*return*/, response.data.Hash];
101
100
  case 2:
102
101
  error_2 = _a.sent();
103
102
  FirmaUtil_1.FirmaUtil.printLog(error_2);
@@ -109,16 +108,24 @@ var IpfsService = /** @class */ (function () {
109
108
  };
110
109
  IpfsService.prototype.addFile = function (fileUrl) {
111
110
  return __awaiter(this, void 0, void 0, function () {
112
- var data, result, error_3;
111
+ var FormData_3, bodyData, fileBuffer, response, error_3;
113
112
  return __generator(this, function (_a) {
114
113
  switch (_a.label) {
115
114
  case 0:
116
115
  _a.trys.push([0, 2, , 3]);
117
- data = fs_1.default.readFileSync(fileUrl);
118
- return [4 /*yield*/, this.ipfsNodeClient.add(data)];
116
+ FormData_3 = require('form-data');
117
+ bodyData = new FormData_3();
118
+ fileBuffer = fs_1.default.readFileSync(fileUrl);
119
+ bodyData.append('file', fileBuffer);
120
+ return [4 /*yield*/, axios_1.default.request({
121
+ url: this.getBasePostUrl(),
122
+ method: 'POST',
123
+ headers: bodyData.getHeaders(),
124
+ data: bodyData
125
+ })];
119
126
  case 1:
120
- result = _a.sent();
121
- return [2 /*return*/, result.cid.toString()];
127
+ response = _a.sent();
128
+ return [2 /*return*/, response.data.Hash];
122
129
  case 2:
123
130
  error_3 = _a.sent();
124
131
  FirmaUtil_1.FirmaUtil.printLog(error_3);
@@ -128,55 +135,6 @@ var IpfsService = /** @class */ (function () {
128
135
  });
129
136
  });
130
137
  };
131
- IpfsService.prototype.getFile = function (hash) {
132
- var e_1, _a;
133
- return __awaiter(this, void 0, void 0, function () {
134
- var stream, data, stream_1, stream_1_1, chunk, e_1_1, error_4;
135
- return __generator(this, function (_b) {
136
- switch (_b.label) {
137
- case 0:
138
- _b.trys.push([0, 13, , 14]);
139
- stream = this.ipfsNodeClient.get(hash);
140
- data = "";
141
- _b.label = 1;
142
- case 1:
143
- _b.trys.push([1, 6, 7, 12]);
144
- stream_1 = __asyncValues(stream);
145
- _b.label = 2;
146
- case 2: return [4 /*yield*/, stream_1.next()];
147
- case 3:
148
- if (!(stream_1_1 = _b.sent(), !stream_1_1.done)) return [3 /*break*/, 5];
149
- chunk = stream_1_1.value;
150
- data += chunk.toString();
151
- _b.label = 4;
152
- case 4: return [3 /*break*/, 2];
153
- case 5: return [3 /*break*/, 12];
154
- case 6:
155
- e_1_1 = _b.sent();
156
- e_1 = { error: e_1_1 };
157
- return [3 /*break*/, 12];
158
- case 7:
159
- _b.trys.push([7, , 10, 11]);
160
- if (!(stream_1_1 && !stream_1_1.done && (_a = stream_1.return))) return [3 /*break*/, 9];
161
- return [4 /*yield*/, _a.call(stream_1)];
162
- case 8:
163
- _b.sent();
164
- _b.label = 9;
165
- case 9: return [3 /*break*/, 11];
166
- case 10:
167
- if (e_1) throw e_1.error;
168
- return [7 /*endfinally*/];
169
- case 11: return [7 /*endfinally*/];
170
- case 12: return [2 /*return*/, data];
171
- case 13:
172
- error_4 = _b.sent();
173
- FirmaUtil_1.FirmaUtil.printLog(error_4);
174
- throw error_4;
175
- case 14: return [2 /*return*/];
176
- }
177
- });
178
- });
179
- };
180
138
  IpfsService.prototype.getURLFromHash = function (hash) {
181
139
  return this.config.ipfsWebApiAddress + "/ipfs/" + hash;
182
140
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@firmachain/firma-js",
3
- "version": "0.2.36",
3
+ "version": "0.2.39",
4
4
  "description": "The Official FirmaChain Javascript SDK written in Typescript",
5
5
  "main": "dist/index.js",
6
6
  "typings": "dist/index.d.ts",
@@ -37,10 +37,10 @@
37
37
  "@cosmjs/proto-signing": "^0.25.6",
38
38
  "@cosmjs/tendermint-rpc": "^0.26.0",
39
39
  "@types/pako": "^2.0.0",
40
- "axios": "^0.21.4",
40
+ "axios": "^0.27.2",
41
41
  "cosmjs-types": "^0.2.0",
42
42
  "crypto-js": "^4.1.1",
43
- "ipfs-http-client": "^52.0.5",
43
+ "form-data": "^4.0.0",
44
44
  "pako": "^2.0.2",
45
45
  "protobufjs": "^6.10.2",
46
46
  "readline-sync": "^1.4.10"