@onekeyfe/onekey-tron-provider 2.2.41 → 2.2.42

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.
@@ -42,6 +42,8 @@ declare class ProviderTron extends ProviderTronBase implements IProviderTron {
42
42
  private _requestAccounts;
43
43
  request<T>(args: RequestArguments): Promise<T>;
44
44
  sign(transaction: UnsignedTransaction): Promise<SignedTransaction>;
45
+ signMessage(transaction: UnsignedTransaction): Promise<string>;
46
+ signMessageV2(message: string | Uint8Array | Array<number>): Promise<string>;
45
47
  getNodeInfo(callback: Callback): Promise<unknown>;
46
48
  }
47
49
  export { ProviderTron };
@@ -42,6 +42,8 @@ class OneKeyTronWeb extends TronWeb {
42
42
  base58: false,
43
43
  };
44
44
  this.trx.sign = (transaction) => provider.sign(transaction);
45
+ this.trx.signMessage = (transaction) => provider.signMessage(transaction);
46
+ this.trx.signMessageV2 = (message, privateKey) => provider.signMessageV2(message, privateKey);
45
47
  this.trx.getNodeInfo = (callback) => provider.getNodeInfo(callback);
46
48
  }
47
49
  request(args) {
@@ -318,12 +320,58 @@ class ProviderTron extends ProviderTronBase {
318
320
  }
319
321
  sign(transaction) {
320
322
  return __awaiter(this, void 0, void 0, function* () {
323
+ var _a, _b;
324
+ if ((_a = this.tronWeb) === null || _a === void 0 ? void 0 : _a.utils.isString(transaction)) {
325
+ // @ts-ignore
326
+ if (!((_b = this.tronWeb) === null || _b === void 0 ? void 0 : _b.utils.isHex(transaction))) {
327
+ throw new Error('Expected hex message input');
328
+ }
329
+ return this.request({
330
+ method: 'signMessageV1',
331
+ params: transaction,
332
+ });
333
+ }
321
334
  return this.request({
322
335
  method: 'tron_signTransaction',
323
336
  params: transaction,
324
337
  });
325
338
  });
326
339
  }
340
+ signMessage(transaction) {
341
+ return __awaiter(this, void 0, void 0, function* () {
342
+ let messageStr;
343
+ if (typeof transaction === 'string') {
344
+ messageStr = transaction;
345
+ }
346
+ else {
347
+ throw new Error('Expected hex message input');
348
+ }
349
+ return this.request({
350
+ method: 'signMessageV1',
351
+ params: [messageStr],
352
+ });
353
+ });
354
+ }
355
+ signMessageV2(message) {
356
+ return __awaiter(this, void 0, void 0, function* () {
357
+ var _a, _b, _c;
358
+ let messageStr;
359
+ if (typeof message === 'string') {
360
+ const bytes = (_c = (_b = (_a = this.tronWeb) === null || _a === void 0 ? void 0 : _a.utils) === null || _b === void 0 ? void 0 : _b.ethersUtils) === null || _c === void 0 ? void 0 : _c.toUtf8Bytes(message);
361
+ if (!bytes) {
362
+ throw new Error('Expected message input');
363
+ }
364
+ messageStr = Buffer.from(bytes).toString('hex');
365
+ }
366
+ else {
367
+ messageStr = Buffer.from(message).toString('hex');
368
+ }
369
+ return this.request({
370
+ method: 'signMessageV2',
371
+ params: [messageStr],
372
+ });
373
+ });
374
+ }
327
375
  getNodeInfo(callback) {
328
376
  return __awaiter(this, void 0, void 0, function* () {
329
377
  const info = yield this.request({
@@ -50,6 +50,8 @@ class OneKeyTronWeb extends tronweb_1.TronWeb {
50
50
  base58: false,
51
51
  };
52
52
  this.trx.sign = (transaction) => provider.sign(transaction);
53
+ this.trx.signMessage = (transaction) => provider.signMessage(transaction);
54
+ this.trx.signMessageV2 = (message, privateKey) => provider.signMessageV2(message, privateKey);
53
55
  this.trx.getNodeInfo = (callback) => provider.getNodeInfo(callback);
54
56
  }
55
57
  request(args) {
@@ -326,12 +328,58 @@ class ProviderTron extends ProviderTronBase_1.ProviderTronBase {
326
328
  }
327
329
  sign(transaction) {
328
330
  return __awaiter(this, void 0, void 0, function* () {
331
+ var _a, _b;
332
+ if ((_a = this.tronWeb) === null || _a === void 0 ? void 0 : _a.utils.isString(transaction)) {
333
+ // @ts-ignore
334
+ if (!((_b = this.tronWeb) === null || _b === void 0 ? void 0 : _b.utils.isHex(transaction))) {
335
+ throw new Error('Expected hex message input');
336
+ }
337
+ return this.request({
338
+ method: 'signMessageV1',
339
+ params: transaction,
340
+ });
341
+ }
329
342
  return this.request({
330
343
  method: 'tron_signTransaction',
331
344
  params: transaction,
332
345
  });
333
346
  });
334
347
  }
348
+ signMessage(transaction) {
349
+ return __awaiter(this, void 0, void 0, function* () {
350
+ let messageStr;
351
+ if (typeof transaction === 'string') {
352
+ messageStr = transaction;
353
+ }
354
+ else {
355
+ throw new Error('Expected hex message input');
356
+ }
357
+ return this.request({
358
+ method: 'signMessageV1',
359
+ params: [messageStr],
360
+ });
361
+ });
362
+ }
363
+ signMessageV2(message) {
364
+ return __awaiter(this, void 0, void 0, function* () {
365
+ var _a, _b, _c;
366
+ let messageStr;
367
+ if (typeof message === 'string') {
368
+ const bytes = (_c = (_b = (_a = this.tronWeb) === null || _a === void 0 ? void 0 : _a.utils) === null || _b === void 0 ? void 0 : _b.ethersUtils) === null || _c === void 0 ? void 0 : _c.toUtf8Bytes(message);
369
+ if (!bytes) {
370
+ throw new Error('Expected message input');
371
+ }
372
+ messageStr = Buffer.from(bytes).toString('hex');
373
+ }
374
+ else {
375
+ messageStr = Buffer.from(message).toString('hex');
376
+ }
377
+ return this.request({
378
+ method: 'signMessageV2',
379
+ params: [messageStr],
380
+ });
381
+ });
382
+ }
335
383
  getNodeInfo(callback) {
336
384
  return __awaiter(this, void 0, void 0, function* () {
337
385
  const info = yield this.request({
package/dist/types.d.ts CHANGED
@@ -46,6 +46,8 @@ export interface IProviderTron extends ProviderTronBase {
46
46
  ready: boolean;
47
47
  request<T>(args: RequestArguments): Promise<T>;
48
48
  sign(transaction: UnsignedTransaction): Promise<SignedTransaction>;
49
+ signMessage(transaction: UnsignedTransaction): Promise<string>;
50
+ signMessageV2(message: string | Uint8Array | Array<number>, privateKey?: string | false): Promise<string>;
49
51
  getNodeInfo(callback?: Callback): Promise<any>;
50
52
  }
51
53
  export interface requestAccountsResponse {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@onekeyfe/onekey-tron-provider",
3
- "version": "2.2.41",
3
+ "version": "2.2.42",
4
4
  "keywords": [
5
5
  "cross-inpage-provider"
6
6
  ],
@@ -28,10 +28,10 @@
28
28
  },
29
29
  "dependencies": {
30
30
  "@noble/secp256k1": "1.7.1",
31
- "@onekeyfe/cross-inpage-provider-core": "2.2.41",
32
- "@onekeyfe/cross-inpage-provider-errors": "2.2.41",
33
- "@onekeyfe/cross-inpage-provider-types": "2.2.41",
34
- "@onekeyfe/extension-bridge-injected": "2.2.41",
31
+ "@onekeyfe/cross-inpage-provider-core": "2.2.42",
32
+ "@onekeyfe/cross-inpage-provider-errors": "2.2.42",
33
+ "@onekeyfe/cross-inpage-provider-types": "2.2.42",
34
+ "@onekeyfe/extension-bridge-injected": "2.2.42",
35
35
  "lodash-es": "^4.17.21",
36
36
  "querystring": "^0.2.1",
37
37
  "sunweb": "^1.0.7",
@@ -40,5 +40,5 @@
40
40
  "devDependencies": {
41
41
  "@types/lodash-es": "^4.17.12"
42
42
  },
43
- "gitHead": "b4200d7f74d3d74acfd2aaedc631841db1c95b38"
43
+ "gitHead": "2328c9b0b1d9b67abe7abf795ef40d793d537627"
44
44
  }