@startbahn/startrail-sdk-js 1.25.1 → 1.25.2

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.
@@ -165579,21 +165579,24 @@ class Service {
165579
165579
  * Sign message with the Ethereum private key associated to your wallet
165580
165580
  * @throws Will throw an error
165581
165581
  */
165582
- signMessage(message, isPopup) {
165582
+ signMessage(message, disableCustomPrefix) {
165583
165583
  return __awaiter(this, void 0, void 0, function* () {
165584
165584
  let customMessage = { message: '', prefix: '' };
165585
- let messageHash;
165586
- if (!isPopup) {
165585
+ let paramsToBeSigned;
165586
+ if (this.wallet === undefined)
165587
+ throw new error_1.CustomError(Error(constant_1.StartrailSdkErrorCodeEnum.WALLET_NOT_INITIALIZED)).sdk();
165588
+ const wallet = this.wallet.wallet;
165589
+ if (!disableCustomPrefix && wallet instanceof torus_1.default) {
165587
165590
  // For customPrefix in defined in torus-embed
165588
165591
  customMessage = util_1.createCustomMessage(globalThis.location.hostname, message);
165589
- messageHash = util_1.generateMessageHash(customMessage.message);
165592
+ paramsToBeSigned = [wallet.EOA, util_1.generateMessageHash(customMessage.message), { customPrefix: customMessage.prefix, customMessage: message }];
165590
165593
  }
165591
165594
  else {
165592
- messageHash = util_1.generateMessageHash(message);
165595
+ paramsToBeSigned = [wallet.EOA, util_1.generateMessageHash(message)];
165593
165596
  }
165594
165597
  try {
165595
- const signature = yield this.wallet.signMessage(messageHash, message, (customMessage.prefix || undefined));
165596
- return { signature, prefix: customMessage.prefix };
165598
+ const signature = yield this.wallet.signMessage(paramsToBeSigned);
165599
+ return { signature, prefix: customMessage.prefix || undefined };
165597
165600
  }
165598
165601
  catch (error) {
165599
165602
  return this._throwExceptionOrReturnFalse(error);
@@ -165926,16 +165929,18 @@ class Startrail {
165926
165929
  }
165927
165930
  /**
165928
165931
  * Sign message with the Ethereum private key associated to your wallet
165932
+ * @param message Original message to be signed
165933
+ * @param disableCustomPrefix Default adds a custom prefix to the message so that Startrail/Torus wallet allows signing without popup consent
165929
165934
  * @throws Will throw an error
165930
165935
  */
165931
- signMessage(message, isPopup) {
165936
+ signMessage(message, disableCustomPrefix) {
165932
165937
  return __awaiter(this, void 0, void 0, function* () {
165933
165938
  if (this.store.torusStatus.popupInprogress)
165934
165939
  return false;
165935
165940
  this.store.switchPopupState();
165936
165941
  try {
165937
165942
  yield this.service.initAndLogin();
165938
- return yield this.service.signMessage(message, isPopup);
165943
+ return yield this.service.signMessage(message, disableCustomPrefix);
165939
165944
  }
165940
165945
  finally {
165941
165946
  this.store.switchPopupState();
@@ -166464,12 +166469,11 @@ class WalletBuilder {
166464
166469
  * @param hashedMessage
166465
166470
  * @todo Fix d.ts in @toruslabs/torus-embed
166466
166471
  */
166467
- signMessage(messageHash, message, customPrefix) {
166472
+ signMessage(params) {
166468
166473
  return __awaiter(this, void 0, void 0, function* () {
166469
166474
  if (this.wallet === undefined)
166470
166475
  throw new error_1.CustomError(Error(constant_1.StartrailSdkErrorCodeEnum.WALLET_NOT_INITIALIZED)).sdk();
166471
- const params = customPrefix ? [this.wallet.EOA, messageHash, { customPrefix, customMessage: message }] : [this.wallet.EOA, messageHash];
166472
- return this.wallet.signMessage(this.wallet.EOA, params);
166476
+ return this.wallet.signMessage(params);
166473
166477
  });
166474
166478
  }
166475
166479
  signTypedDataMessage(typedData) {
@@ -166534,14 +166538,14 @@ class Wallet {
166534
166538
  this.EOA = '';
166535
166539
  this.initialEOA = ''; // To detect EOA switched from the initial to different one with browser based extension wallets such as Metamask
166536
166540
  }
166537
- signMessage(eoa, params) {
166541
+ signMessage(params) {
166538
166542
  return __awaiter(this, void 0, void 0, function* () {
166539
166543
  const web3 = new web3_1.default(this.provider);
166540
166544
  return yield (() => new Promise((resolve, reject) => {
166541
166545
  web3.currentProvider.send({
166542
166546
  method: 'eth_sign',
166543
166547
  params,
166544
- from: eoa
166548
+ from: this.EOA
166545
166549
  }, (err, res) => {
166546
166550
  if (err) {
166547
166551
  reject(err);
@@ -166666,13 +166670,13 @@ class Metamask extends base_1.default {
166666
166670
  };
166667
166671
  });
166668
166672
  }
166669
- signMessage(eoa, params) {
166673
+ signMessage(params) {
166670
166674
  const _super = Object.create(null, {
166671
166675
  signMessage: { get: () => super.signMessage }
166672
166676
  });
166673
166677
  return __awaiter(this, void 0, void 0, function* () {
166674
166678
  try {
166675
- return yield _super.signMessage.call(this, eoa, params);
166679
+ return yield _super.signMessage.call(this, params);
166676
166680
  }
166677
166681
  catch (e) {
166678
166682
  throw new error_1.CustomError(e).sdk();
@@ -166855,13 +166859,13 @@ class Torus extends base_1.default {
166855
166859
  * @param hashedMessage
166856
166860
  * @todo Fix d.ts in @toruslabs/torus-embed
166857
166861
  */
166858
- signMessage(eoa, params) {
166862
+ signMessage(params) {
166859
166863
  const _super = Object.create(null, {
166860
166864
  signMessage: { get: () => super.signMessage }
166861
166865
  });
166862
166866
  return __awaiter(this, void 0, void 0, function* () {
166863
166867
  try {
166864
- return yield _super.signMessage.call(this, eoa, params);
166868
+ return yield _super.signMessage.call(this, params);
166865
166869
  }
166866
166870
  catch (e) {
166867
166871
  throw new error_1.CustomError(e).torus();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@startbahn/startrail-sdk-js",
3
- "version": "1.25.1",
3
+ "version": "1.25.2",
4
4
  "description": "Startrail Api for JS SDK",
5
5
  "main": "dist/startrail-sdk.js",
6
6
  "unpkg": "dist/startrail-sdk.js",
@@ -29,9 +29,11 @@ declare module '@startbahn/startrail-sdk-js' {
29
29
  getUserInfo(): Promise<Type.UserInfo | false>;
30
30
  /**
31
31
  * Sign message with the Ethereum private key associated to your wallet
32
+ * @param message Original message to be signed
33
+ * @param disableCustomPrefix Default adds a custom prefix to the message so that Startrail/Torus wallet allows signing without popup consent
32
34
  * @throws Will throw an error
33
35
  */
34
- signMessage(message: string, isPopup?: boolean): Promise<Type.MessageSignature | false>;
36
+ signMessage(message: string, disableCustomPrefix?: boolean): Promise<Type.MessageSignature | false>;
35
37
  /**
36
38
  * Create SRR
37
39
  * Send tx to Startrail Ethereum smart-contract with meta-tx in which signature is generated by your private key
@@ -288,8 +290,12 @@ declare module '@startbahn/startrail-sdk-js/types' {
288
290
  }
289
291
  export interface MessageSignature {
290
292
  signature: string;
291
- prefix?: string;
293
+ prefix: string | undefined;
292
294
  }
295
+ export type MessageToBeSigned = [string, string] | [string, string, {
296
+ customPrefix: string;
297
+ customMessage: string;
298
+ }];
293
299
  export interface startrailLUWAddress {
294
300
  startrailLUWAddress: string;
295
301
  }
@@ -645,7 +651,7 @@ declare module '@startbahn/startrail-sdk-js/service' {
645
651
  * Sign message with the Ethereum private key associated to your wallet
646
652
  * @throws Will throw an error
647
653
  */
648
- signMessage(message: string, isPopup?: boolean): Promise<Type.MessageSignature | false>;
654
+ signMessage(message: string, disableCustomPrefix?: boolean): Promise<Type.MessageSignature | false>;
649
655
  /**
650
656
  * Sign typed data according to EIP-712 standard
651
657
  */
@@ -800,7 +806,7 @@ declare module '@startbahn/startrail-sdk-js/errorClass' {
800
806
  }
801
807
 
802
808
  declare module '@startbahn/startrail-sdk-js/walletBuilder' {
803
- import { EIP712TypedData, Language, OverwriteStartrailSDKConfig, UserInfo } from '@startbahn/startrail-sdk-js/types';
809
+ import { EIP712TypedData, Language, MessageToBeSigned, OverwriteStartrailSDKConfig, UserInfo } from '@startbahn/startrail-sdk-js/types';
804
810
  import Wallet from '@startbahn/startrail-sdk-js/wallets/base';
805
811
  class WalletBuilder {
806
812
  wallet?: Wallet;
@@ -831,7 +837,7 @@ declare module '@startbahn/startrail-sdk-js/walletBuilder' {
831
837
  * @param hashedMessage
832
838
  * @todo Fix d.ts in @toruslabs/torus-embed
833
839
  */
834
- signMessage(messageHash: string, message: string, customPrefix: string | undefined): Promise<string>;
840
+ signMessage(params: MessageToBeSigned): Promise<string>;
835
841
  signTypedDataMessage(typedData: EIP712TypedData): Promise<string>;
836
842
  /**
837
843
  * Change language on your browser wallet if it's provided
@@ -1019,7 +1025,7 @@ declare module '@startbahn/startrail-sdk-js/constant' {
1019
1025
  }
1020
1026
 
1021
1027
  declare module '@startbahn/startrail-sdk-js/wallets/base' {
1022
- import { EIP712TypedData, OverwriteStartrailSDKConfig, UserInfo } from '@startbahn/startrail-sdk-js/types';
1028
+ import { EIP712TypedData, MessageToBeSigned, OverwriteStartrailSDKConfig, UserInfo } from '@startbahn/startrail-sdk-js/types';
1023
1029
  abstract class Wallet {
1024
1030
  EOA: string;
1025
1031
  initialEOA: string;
@@ -1028,7 +1034,7 @@ declare module '@startbahn/startrail-sdk-js/wallets/base' {
1028
1034
  abstract init(): Promise<void>;
1029
1035
  abstract login(): Promise<string[]>;
1030
1036
  abstract getUserInfo(): Promise<UserInfo>;
1031
- signMessage(eoa: string, params: object): Promise<string>;
1037
+ signMessage(params: MessageToBeSigned): Promise<string>;
1032
1038
  signTypedDataMessage(eoa: string, typedData: EIP712TypedData): Promise<string>;
1033
1039
  logout(): Promise<void>;
1034
1040
  overwriteConfig(partialConfig: OverwriteStartrailSDKConfig): void;