@startbahn/startrail-sdk-js 1.34.0 → 1.35.0

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.
package/README.md CHANGED
@@ -42,8 +42,8 @@ const startrail = new Startrail(params)
42
42
  - `startrail`: Google or Email/Passord powered by TORUS.
43
43
  - `env` (optional): Environment that impacts on blockchain network, and EOA with startrail Email/Password
44
44
  - `production`: Matic network. TORUS production account and Startrail production Auth0 account. It is designed to communicate to Startrail production API.
45
- - `staging`: Mumbai network. TORUS production account and Startrail staging Auth0 account. It is designed to communicate to Startrail staging API.
46
- - `lrc`: Mumbai network. TORUS lrc account and Startrail qa Auth0 account. It is designed to communicate to Startrail qa API.
45
+ - `staging`: Amoy network. TORUS production account and Startrail staging Auth0 account. It is designed to communicate to Startrail staging API.
46
+ - `lrc`: Amoy network. TORUS lrc account and Startrail qa Auth0 account. It is designed to communicate to Startrail qa API.
47
47
  - `local`: https://localhost:8545 network for local dev. TORUS lrc account and Startrail lrc Auth0 account. It is designed to communicate to localhost API.
48
48
 
49
49
  [For Startrail wallet powered by TORUS]
@@ -70,6 +70,7 @@ const startrail = new Startrail(params)
70
70
  - `callbackUrl` (optional): Callback URL to redirect to from E-Mail template for signup verification
71
71
  - `withModal` (optional): Specifies if the Torus Login Provider Modal should be shown. Default value is set to `false`
72
72
  - `rpcEndpoint` (optional): RpcEndpoint that is accessed from the wallet you login/signup
73
+ - `chainId` (optional): chainId of EVM based blockchain that is accessed from the wallet you login/signup
73
74
 
74
75
  [To be deprecate]
75
76
  - `torusBuildEnv` (optional): Alias for `env`.
@@ -10479,6 +10479,7 @@ module.exports["default"] = AbortController
10479
10479
  /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
10480
10480
 
10481
10481
  "use strict";
10482
+ /* provided dependency */ var process = __webpack_require__(4155);
10482
10483
  // Currently in sync with Node.js lib/assert.js
10483
10484
  // https://github.com/nodejs/node/commit/2a51ae424a513ec9a6aa3466baa0cc1d55dd4f3b
10484
10485
 
@@ -11076,6 +11077,7 @@ assert.strict.strict = assert.strict;
11076
11077
  /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
11077
11078
 
11078
11079
  "use strict";
11080
+ /* provided dependency */ var process = __webpack_require__(4155);
11079
11081
  // Currently in sync with Node.js lib/internal/assert/assertion_error.js
11080
11082
  // https://github.com/nodejs/node/commit/0817840f775032169ddd70c85ac059f18ffcc81c
11081
11083
 
@@ -16048,6 +16050,7 @@ if (typeof self === 'object') {
16048
16050
 
16049
16051
  "use strict";
16050
16052
  /* provided dependency */ var Buffer = __webpack_require__(8764)["Buffer"];
16053
+ /* provided dependency */ var process = __webpack_require__(4155);
16051
16054
 
16052
16055
  /* eslint camelcase: "off" */
16053
16056
 
@@ -16464,6 +16467,7 @@ exports.Zlib = Zlib;
16464
16467
  /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
16465
16468
 
16466
16469
  "use strict";
16470
+ /* provided dependency */ var process = __webpack_require__(4155);
16467
16471
 
16468
16472
 
16469
16473
  var Buffer = (__webpack_require__(8764).Buffer);
@@ -23523,6 +23527,7 @@ utils.intFromLE = intFromLE;
23523
23527
  /***/ 2840:
23524
23528
  /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
23525
23529
 
23530
+ /* provided dependency */ var process = __webpack_require__(4155);
23526
23531
  var once = __webpack_require__(778);
23527
23532
 
23528
23533
  var noop = function() {};
@@ -42229,6 +42234,7 @@ process.umask = function() { return 0; };
42229
42234
  /***/ 4286:
42230
42235
  /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
42231
42236
 
42237
+ /* provided dependency */ var process = __webpack_require__(4155);
42232
42238
  var once = __webpack_require__(778)
42233
42239
  var eos = __webpack_require__(2840)
42234
42240
  var fs = __webpack_require__(1156) // we only need fs to get the ReadStream and WriteStream prototypes
@@ -42319,6 +42325,7 @@ module.exports = pump
42319
42325
  /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
42320
42326
 
42321
42327
  "use strict";
42328
+ /* provided dependency */ var process = __webpack_require__(4155);
42322
42329
 
42323
42330
 
42324
42331
  // limit of Crypto.getRandomValues()
@@ -42512,6 +42519,7 @@ module.exports.q = codes;
42512
42519
  /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
42513
42520
 
42514
42521
  "use strict";
42522
+ /* provided dependency */ var process = __webpack_require__(4155);
42515
42523
  // Copyright Joyent, Inc. and other Node contributors.
42516
42524
  //
42517
42525
  // Permission is hereby granted, free of charge, to any person obtaining a
@@ -42689,6 +42697,7 @@ PassThrough.prototype._transform = function (chunk, encoding, cb) {
42689
42697
  /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
42690
42698
 
42691
42699
  "use strict";
42700
+ /* provided dependency */ var process = __webpack_require__(4155);
42692
42701
  // Copyright Joyent, Inc. and other Node contributors.
42693
42702
  //
42694
42703
  // Permission is hereby granted, free of charge, to any person obtaining a
@@ -43920,6 +43929,7 @@ function done(stream, er, data) {
43920
43929
  /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
43921
43930
 
43922
43931
  "use strict";
43932
+ /* provided dependency */ var process = __webpack_require__(4155);
43923
43933
  // Copyright Joyent, Inc. and other Node contributors.
43924
43934
  //
43925
43935
  // Permission is hereby granted, free of charge, to any person obtaining a
@@ -44568,6 +44578,7 @@ Writable.prototype._destroy = function (err, cb) {
44568
44578
  /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
44569
44579
 
44570
44580
  "use strict";
44581
+ /* provided dependency */ var process = __webpack_require__(4155);
44571
44582
 
44572
44583
 
44573
44584
  var _Object$setPrototypeO;
@@ -44942,9 +44953,10 @@ module.exports = /*#__PURE__*/function () {
44942
44953
  /***/ }),
44943
44954
 
44944
44955
  /***/ 1195:
44945
- /***/ ((module) => {
44956
+ /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
44946
44957
 
44947
44958
  "use strict";
44959
+ /* provided dependency */ var process = __webpack_require__(4155);
44948
44960
 
44949
44961
 
44950
44962
  // undocumented cb() API, needed for core, not for public API
@@ -51831,6 +51843,7 @@ exports.isAnyArrayBuffer = isAnyArrayBuffer;
51831
51843
  /***/ 9539:
51832
51844
  /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
51833
51845
 
51846
+ /* provided dependency */ var process = __webpack_require__(4155);
51834
51847
  // Copyright Joyent, Inc. and other Node contributors.
51835
51848
  //
51836
51849
  // Permission is hereby granted, free of charge, to any person obtaining a
@@ -52888,6 +52901,7 @@ __webpack_require__.r(__webpack_exports__);
52888
52901
  // EXPORTS
52889
52902
  __webpack_require__.d(__webpack_exports__, {
52890
52903
  Auth0VerifyEmail: () => (/* reexport */ Auth0VerifyEmail),
52904
+ JSON_RPC_ERROR: () => (/* reexport */ JSON_RPC_ERROR),
52891
52905
  METADATA_VALIDATION_FAILED: () => (/* reexport */ METADATA_VALIDATION_FAILED),
52892
52906
  Others: () => (/* reexport */ Others),
52893
52907
  Startrail: () => (/* binding */ Startrail),
@@ -54047,7 +54061,8 @@ const ERROR_MESSAGE = {
54047
54061
  // Formalized status code under https://eips.ethereum.org/EIPS/eip-1193#provider-errors
54048
54062
  const ERROR_STATUS_CODE = {
54049
54063
  USER_REJECTED_REQUEST: 4001,
54050
- METADATA_VALIDATION_FAILED: 400
54064
+ METADATA_VALIDATION_FAILED: 400,
54065
+ CHAINID_MISMATCH: -32603
54051
54066
  };
54052
54067
  // See: https://chainlist.org/chain/137 OR https://www.alchemy.com/chain-connect/chain/polygon-pos
54053
54068
  // recommended order
@@ -54060,19 +54075,14 @@ const RPC_URLS = {
54060
54075
  'https://polygon.llamarpc.com',
54061
54076
  'https://rpc-mainnet.matic.quiknode.pro',
54062
54077
  ],
54063
- // See https://www.alchemy.com/chain-connect/chain/mumbai OR https://chainlist.org/chain/137
54064
54078
  DEV: [
54065
- 'https://endpoints.omniatech.io/v1/matic/mumbai/public',
54066
- 'https://polygon-mumbai.g.alchemy.com/v2/demo',
54067
- 'https://polygon-mumbai.blockpi.network/v1/rpc/public',
54068
- 'https://rpc-mumbai.maticvigil.com',
54069
- 'https://rpc.ankr.com/polygon_mumbai',
54079
+ 'https://polygon-amoy.infura.io/v3/693b51fa95334eb3bb1849da03cef748', // Infura RPC managed by Startbahn
54070
54080
  ]
54071
54081
  };
54072
54082
  // Host name and chainId pair is defined and validated in torus-website.
54073
54083
  const ETHEREUM_NETWORK = {
54074
54084
  PROD: { rpc: RPC_URLS.PROD[0], chainId: 137, name: 'Polygon Mainnet' },
54075
- DEV: { rpc: RPC_URLS.DEV[0], chainId: 80001, name: 'Mumbai' },
54085
+ DEV: { rpc: RPC_URLS.DEV[0], chainId: 80002, name: 'Polygon Amoy Testnet' },
54076
54086
  LOCAL: { rpc: 'https://localhost:8545', chainId: 5777, name: 'Local' }
54077
54087
  };
54078
54088
  const GCS_URL = {
@@ -54128,6 +54138,8 @@ var StartrailSdkErrorCodeEnum;
54128
54138
  StartrailSdkErrorCodeEnum["WALLET_RPC_CONNECTION_FAILURE"] = "WALLET_RPC_CONNECTION_FAILURE";
54129
54139
  StartrailSdkErrorCodeEnum["WALLET_USER_REJECT_WALLET_REQUEST"] = "WALLET_USER_REJECT_WALLET_REQUEST";
54130
54140
  StartrailSdkErrorCodeEnum["METADATA_VALIDATION_FAILED"] = "METADATA_VALIDATION_FAILED";
54141
+ StartrailSdkErrorCodeEnum["JSON_RPC_ERROR"] = "JSON_RPC_ERROR";
54142
+ StartrailSdkErrorCodeEnum["CHAINID_MISMATCH"] = "CHAINID_MISMATCH";
54131
54143
  })(StartrailSdkErrorCodeEnum || (StartrailSdkErrorCodeEnum = {}));
54132
54144
  const TORUS_VERIFIERS = {
54133
54145
  google: {
@@ -54330,6 +54342,17 @@ class METADATA_VALIDATION_FAILED extends StartrailSdkErrorBase {
54330
54342
  this.property = { message: err.message };
54331
54343
  }
54332
54344
  }
54345
+ class JSON_RPC_ERROR extends StartrailSdkErrorBase {
54346
+ errorCode;
54347
+ constructor(err) {
54348
+ super(err.message);
54349
+ this.errorCode =
54350
+ err.code === ERROR_STATUS_CODE.CHAINID_MISMATCH ?
54351
+ StartrailSdkErrorCodeEnum.CHAINID_MISMATCH
54352
+ : StartrailSdkErrorCodeEnum.JSON_RPC_ERROR;
54353
+ this.property = { message: err?.message, stack: err?.stack };
54354
+ }
54355
+ }
54333
54356
  class Others extends StartrailSdkErrorBase {
54334
54357
  errorCode;
54335
54358
  constructor(err) {
@@ -54812,6 +54835,8 @@ class CustomError {
54812
54835
  throw new TORUS_THIRD_PARTY_COOKIES_UNSUPPORTED(this.err);
54813
54836
  case argument === trimStringWord(ERROR_MESSAGE.TORUS_FAILS_INIT):
54814
54837
  throw new TORUS_FAILS_INIT(this.err);
54838
+ case argument === 'internaljson-rpcerror' && !!this.err?.data?.cause:
54839
+ throw new JSON_RPC_ERROR({ code: this.err.code, message: this.err.data.cause.message, stack: this.err.data.cause.stack });
54815
54840
  case RegExp(trimStringWord(ERROR_MESSAGE.TORUS_CACHE_CONTROL_HEADERS_UNMATCH)).test(argument):
54816
54841
  throw new TORUS_CACHE_CONTROL_HEADERS_UNMATCH(this.err);
54817
54842
  default:
@@ -54845,6 +54870,8 @@ class CustomError {
54845
54870
  case ERROR_STATUS_CODE.USER_REJECTED_REQUEST:
54846
54871
  // should change to wallet name ? // keep it for backward-compatible ?
54847
54872
  throw new WALLET_USER_REJECT_WALLET_REQUEST(this.err);
54873
+ case ERROR_STATUS_CODE.CHAINID_MISMATCH:
54874
+ throw new JSON_RPC_ERROR({ code: this.err.code, message: this.err.message });
54848
54875
  }
54849
54876
  throw new Others(this.err);
54850
54877
  }
@@ -63896,6 +63923,9 @@ const patchDeprecateParams = (config) => {
63896
63923
  const { torusBuildEnv, ...res } = patchedConf;
63897
63924
  return res;
63898
63925
  };
63926
+ /**
63927
+ * @TODO: This function may be removed just relying on Torus default RPC endpoint
63928
+ */
63899
63929
  const findLiveRpcEndpoint = async (rpcList) => {
63900
63930
  const sendHttpRequest = async (url) => {
63901
63931
  const tx = new transaction(url);
@@ -63935,6 +63965,62 @@ const findEnvByChainId = (chainId) => {
63935
63965
  return 'PROD';
63936
63966
  };
63937
63967
 
63968
+ ;// CONCATENATED MODULE: ./src/configContext/network.ts
63969
+
63970
+ // TODO: Fully grant the liberty for users to overwrite the network configuration: https://startbahn.atlassian.net/browse/STARTRAIL-2738
63971
+ // NOTE: Given that Startrail currently only supports the Polygon main/test-net and network changes, such as from Mumbai to Amoy, do not occur frequently.
63972
+ // To minimize interface changes, the chainName and currency fields are not changeable at the moment. However, MetaMask users have the ability to manually overwrite the chain name within the extension.
63973
+ // (It should also be doable to fetch currencies and chain names programmatically from the chainlist API in future)
63974
+ const blockchainNetwork = (param) => {
63975
+ const { env, rpcEndpoint, chainId } = param;
63976
+ return {
63977
+ host: rpcEndpoint || ETHEREUM_NETWORK[env].rpc,
63978
+ chainId: chainId || ETHEREUM_NETWORK[env].chainId,
63979
+ chainName: ETHEREUM_NETWORK[env].name,
63980
+ nativeCurrency: {
63981
+ name: 'Matic',
63982
+ symbol: 'MATIC',
63983
+ decimals: 18
63984
+ },
63985
+ };
63986
+ };
63987
+ function network_create(param) {
63988
+ if (!param.rpcEndpoint && param.chainId) {
63989
+ throw ('rpcEndpoint is required when chainId is provided');
63990
+ }
63991
+ switch (param.env) {
63992
+ case 'staging':
63993
+ return new DevNetwork(param);
63994
+ case 'lrc':
63995
+ return new DevNetwork(param);
63996
+ case 'local':
63997
+ return new LocalNetwork(param);
63998
+ default:
63999
+ return new ProdNetwork(param);
64000
+ }
64001
+ }
64002
+ class Network {
64003
+ data;
64004
+ constructor(param) {
64005
+ this.data = param;
64006
+ }
64007
+ }
64008
+ class ProdNetwork extends Network {
64009
+ get() {
64010
+ return blockchainNetwork({ ...this.data, env: 'PROD' });
64011
+ }
64012
+ }
64013
+ class DevNetwork extends Network {
64014
+ get() {
64015
+ return blockchainNetwork({ ...this.data, env: 'DEV' });
64016
+ }
64017
+ }
64018
+ class LocalNetwork extends Network {
64019
+ get() {
64020
+ return blockchainNetwork({ ...this.data, env: 'LOCAL' });
64021
+ }
64022
+ }
64023
+
63938
64024
  ;// CONCATENATED MODULE: ./src/configContext/torusSocialLogin.ts
63939
64025
 
63940
64026
 
@@ -64062,6 +64148,7 @@ const getCallabckUrl = () => {
64062
64148
 
64063
64149
 
64064
64150
 
64151
+
64065
64152
  /**
64066
64153
  * Config properties for torus-embed init()
64067
64154
  */
@@ -64232,7 +64319,7 @@ class TorusConfigContext {
64232
64319
  const livezRpc = await findLiveRpcEndpoint(rpcUrls);
64233
64320
  if (livezRpc !== this.torusContextConfig.config.network?.host) {
64234
64321
  // TODO: Force all overwriteConfig relevant tasks to go through overwriteConfig function, or remvoe preConfig to restructure config to be more simple.
64235
- this.torusContextConfig.preConfig.network = this.network(this.torusContextConfig.config.buildEnv, livezRpc);
64322
+ this.torusContextConfig.preConfig.network = this.network(this.torusContextConfig.config.buildEnv, livezRpc, this.torusContextConfig.preConfig.network.ethereumNetwork.chainId);
64236
64323
  this.torusContextConfig.config = torusConfig(this.torusContextConfig.preConfig);
64237
64324
  }
64238
64325
  }
@@ -64275,7 +64362,7 @@ class TorusConfigContext {
64275
64362
  ...this.torusContextConfig.preConfig,
64276
64363
  ...{ ...config, lang: config.lang },
64277
64364
  ...{
64278
- network: this.network(this.torusContextConfig.config.buildEnv, config?.rpcEndpoint),
64365
+ network: this.network(this.torusContextConfig.config.buildEnv, config?.rpcEndpoint, config?.chainId),
64279
64366
  loginProvider: restructureLoginConfig(config?.loginProvider),
64280
64367
  conditionalWords: this.convertWordsByAuthProvider(config)
64281
64368
  }
@@ -64285,12 +64372,12 @@ class TorusConfigContext {
64285
64372
  return {
64286
64373
  apiPath: config?.apiPath || STARTRAIL_API,
64287
64374
  authAction: config?.authAction || AUTH0_DEFAULT_TAB,
64288
- auth0ClientId: config?.auth0ClientId || AUTH0_CLIENT_IDS[this.adaptTorusEnvToAppEnv(config?.env)],
64289
- auth0TorusConfigKey: config?.auth0TorusConfigKey || AUTH0_TORUS_CONFIG_KEYS[this.adaptTorusEnvToAppEnv(config?.env)],
64290
- auth0Domain: config?.auth0Domain || AUTH0_DOMAINS[this.adaptTorusEnvToAppEnv(config?.env)],
64375
+ auth0ClientId: config?.auth0ClientId || AUTH0_CLIENT_IDS[this.adaptTorusEnv(config?.env).appEnv],
64376
+ auth0TorusConfigKey: config?.auth0TorusConfigKey || AUTH0_TORUS_CONFIG_KEYS[this.adaptTorusEnv(config?.env).appEnv],
64377
+ auth0Domain: config?.auth0Domain || AUTH0_DOMAINS[this.adaptTorusEnv(config?.env).appEnv],
64291
64378
  lang: (config?.lang !== LANG.JP ? LANG.EN : LANG.JP),
64292
64379
  loginProvider: restructureLoginConfig(config?.loginProvider),
64293
- network: this.network(config?.env, config?.rpcEndpoint),
64380
+ network: this.network(config?.env, config?.rpcEndpoint, config?.chainId),
64294
64381
  callbackUrl: config?.callbackUrl || null,
64295
64382
  withModal: typeof (config?.withModal) === 'boolean' ? config?.withModal : true,
64296
64383
  conditionalWords: this.convertWordsByAuthProvider(config),
@@ -64298,39 +64385,18 @@ class TorusConfigContext {
64298
64385
  mfaLevel: config?.mfaLevel || 'none' // 'none' will skip the mfa setup screen totally. Check https://web3auth.io/docs/sdk/pnp/unreal/mfa#mfalevel
64299
64386
  };
64300
64387
  };
64301
- network(env, rpcEndpoint) {
64302
- const blockchainNetwork = (envKey) => {
64303
- return {
64304
- host: rpcEndpoint || ETHEREUM_NETWORK[envKey].rpc,
64305
- chainId: ETHEREUM_NETWORK[envKey].chainId
64306
- };
64388
+ network(env, rpcEndpointByClient, chainIdByClient) {
64389
+ const networkByEnv = network_create({ env, rpcEndpoint: rpcEndpointByClient, chainId: chainIdByClient });
64390
+ const network = networkByEnv.get();
64391
+ const envs = this.adaptTorusEnv(env);
64392
+ return {
64393
+ torusEnv: envs.torusEnv,
64394
+ appEnv: envs.appEnv,
64395
+ ethereumNetwork: {
64396
+ host: network.host,
64397
+ chainId: network.chainId,
64398
+ }
64307
64399
  };
64308
- switch (env) {
64309
- case 'staging':
64310
- return {
64311
- torusEnv: 'production',
64312
- appEnv: this.adaptTorusEnvToAppEnv(env),
64313
- ethereumNetwork: blockchainNetwork('DEV')
64314
- };
64315
- case 'lrc':
64316
- return {
64317
- torusEnv: 'lrc',
64318
- appEnv: this.adaptTorusEnvToAppEnv(env),
64319
- ethereumNetwork: blockchainNetwork('DEV')
64320
- };
64321
- case 'local':
64322
- return {
64323
- torusEnv: 'lrc',
64324
- appEnv: this.adaptTorusEnvToAppEnv(env),
64325
- ethereumNetwork: blockchainNetwork('LOCAL')
64326
- };
64327
- default:
64328
- return {
64329
- torusEnv: 'production',
64330
- appEnv: this.adaptTorusEnvToAppEnv(),
64331
- ethereumNetwork: blockchainNetwork('PROD')
64332
- };
64333
- }
64334
64400
  }
64335
64401
  /**
64336
64402
  * Some wording is determined by users' action
@@ -64359,16 +64425,19 @@ class TorusConfigContext {
64359
64425
  };
64360
64426
  }
64361
64427
  }
64362
- adaptTorusEnvToAppEnv(env) {
64428
+ // TODO: Consider removing local env if it is not used for local development anymore.
64429
+ adaptTorusEnv(env) {
64363
64430
  switch (env) {
64364
64431
  case 'production':
64365
- return 'PROD';
64432
+ return { appEnv: 'PROD', torusEnv: 'production' };
64366
64433
  case 'staging':
64367
- return 'STG';
64434
+ return { appEnv: 'STG', torusEnv: 'production' };
64368
64435
  case 'lrc':
64369
- return 'DEV';
64436
+ return { appEnv: 'DEV', torusEnv: 'lrc' };
64437
+ case 'local':
64438
+ return { appEnv: 'DEV', torusEnv: 'lrc' };
64370
64439
  default:
64371
- return 'PROD';
64440
+ return { appEnv: 'PROD', torusEnv: 'production' };
64372
64441
  }
64373
64442
  }
64374
64443
  }
@@ -64595,34 +64664,17 @@ var dist_default = /*#__PURE__*/__webpack_require__.n(dist);
64595
64664
  ;// CONCATENATED MODULE: ./src/configContext/metamask.ts
64596
64665
 
64597
64666
 
64598
- function setNetwork(network, rpc) {
64599
- return {
64600
- chainId: convertNumberToHexString(network.chainId),
64601
- chainName: network.name,
64602
- rpcUrls: [rpc || network.rpc],
64603
- nativeCurrency: {
64604
- name: 'Matic',
64605
- symbol: 'MATIC',
64606
- decimals: 18
64607
- }
64608
- };
64609
- }
64610
64667
  class MetamaskConfigContext {
64611
64668
  ethereumNetwork;
64612
64669
  constructor(config) {
64613
- switch (config?.env) {
64614
- case 'staging':
64615
- this.ethereumNetwork = setNetwork(ETHEREUM_NETWORK.DEV, config?.rpcEndpoint);
64616
- break;
64617
- case 'lrc':
64618
- this.ethereumNetwork = setNetwork(ETHEREUM_NETWORK.DEV, config?.rpcEndpoint);
64619
- break;
64620
- case 'local':
64621
- this.ethereumNetwork = setNetwork(ETHEREUM_NETWORK.LOCAL, config?.rpcEndpoint);
64622
- break;
64623
- default: // For Production
64624
- this.ethereumNetwork = setNetwork(ETHEREUM_NETWORK.PROD, config?.rpcEndpoint);
64625
- }
64670
+ const networkByEnv = network_create({ env: config?.env, rpcEndpoint: config?.rpcEndpoint, chainId: config?.chainId });
64671
+ const network = networkByEnv.get();
64672
+ this.ethereumNetwork = {
64673
+ chainId: convertNumberToHexString(network.chainId),
64674
+ chainName: network.chainName,
64675
+ rpcUrls: [network.host],
64676
+ nativeCurrency: network.nativeCurrency,
64677
+ };
64626
64678
  }
64627
64679
  }
64628
64680
  /* harmony default export */ const metamask = (MetamaskConfigContext);
@@ -64712,7 +64764,11 @@ class Metamask extends base {
64712
64764
  }
64713
64765
  }
64714
64766
  /**
64715
- * Request users to set Mumbai or Polygon network if not setup yet
64767
+ * Request users to add the network in MetaMask configuration if not setup yet
64768
+ * @see https://docs.metamask.io/wallet/reference/wallet_addethereumchain/
64769
+ * NOTE: Test network may see "submitted RPC URL value does not match a known provider for this chain ID" warning message
64770
+ * since they may not be listed in https://chainlist.wtf/
64771
+ * @see https://support.metamask.io/hc/en-us/articles/360057142392-Verifying-custom-network-information
64716
64772
  */
64717
64773
  async _switchEthereumChain() {
64718
64774
  const env = findEnvByChainId(Number(this.configContext.ethereumNetwork.chainId));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@startbahn/startrail-sdk-js",
3
- "version": "1.34.0",
3
+ "version": "1.35.0",
4
4
  "description": "Startrail Api for JS SDK",
5
5
  "main": "dist/startrail-sdk.js",
6
6
  "types": "types/startrail-sdk-js.d.ts",
@@ -13,7 +13,7 @@
13
13
  "build:development": "webpack --config ./config/webpack.config.js --mode development",
14
14
  "build:release": "webpack --config ./config/webpack.config.js --mode production",
15
15
  "watch": "yarn lint && webpack --watch",
16
- "test": "yarn build:development && yarn jest",
16
+ "test": "yarn build:development && yarn jest --runInBand --logHeapUsage",
17
17
  "serve": "npx webpack-dev-server --config ./config/webpack.config.js --mode development",
18
18
  "generate-dts": "bin/generate-dts",
19
19
  "publish:beta": "sh bin/publish.sh -e qa",
@@ -111,9 +111,10 @@ declare module '@startbahn/startrail-sdk-js' {
111
111
  declare module '@startbahn/startrail-sdk-js/types' {
112
112
  import { TypedDataDomain, TypedDataField } from '@ethersproject/abstract-signer';
113
113
  import type { TorusParams } from '@toruslabs/torus-embed';
114
- export interface AddCustomHistoriesToSRRs extends ContractAddress, Pick<HTTPHeadersForStartrailLUW, 'startrailLUWContractAddress'> {
114
+ export interface AddCustomHistoriesToSRRs extends Pick<HTTPHeadersForStartrailLUW, 'startrailLUWContractAddress'> {
115
115
  tokenIds: string[];
116
116
  customHistoryIds: string[];
117
+ contractAddress?: string;
117
118
  }
118
119
  export interface AdditionalRequestProps {
119
120
  startrailLUWContractAddress?: string;
@@ -128,13 +129,15 @@ declare module '@startbahn/startrail-sdk-js/types' {
128
129
  signup: boolean;
129
130
  }
130
131
  export interface ApproveSRRByCommitment extends ApproveSRRByCommitmentShared, Pick<HTTPHeadersForStartrail, 'startrailLUWContractAddress'> {
132
+ contractAddress?: string;
131
133
  }
132
- export interface ApproveSRRByCommitmentShared extends ContractAddress {
134
+ export interface ApproveSRRByCommitmentShared {
133
135
  preimage?: string;
134
136
  revealHash?: string;
135
137
  tokenId: string;
136
138
  metadata: HistoryMetadata;
137
139
  isHashPreimageEnabled?: boolean;
140
+ contractAddress?: string;
138
141
  }
139
142
  export interface ApproveSRRByCommitmentDto {
140
143
  metadata: HistoryMetadata;
@@ -150,6 +153,7 @@ declare module '@startbahn/startrail-sdk-js/types' {
150
153
  apiPath?: string;
151
154
  env?: StartrailEnv;
152
155
  rpcEndpoint?: string;
156
+ chainId?: number;
153
157
  }
154
158
  export interface ConvertMetadata {
155
159
  metadataBatch: {
@@ -220,21 +224,21 @@ declare module '@startbahn/startrail-sdk-js/types' {
220
224
  salt: string;
221
225
  };
222
226
  }
223
- interface ContractAddress {
224
- contractAddress?: string;
225
- }
226
227
  export interface CreateSRR extends CreateSRRForRequest, Pick<HTTPHeadersForStartrailLUW, 'startrailLUWContractAddress'> {
228
+ contractAddress?: string;
227
229
  }
228
- export interface CreateSRRForRequest extends ContractAddress {
230
+ export interface CreateSRRForRequest {
229
231
  isPrimaryIssuer: boolean;
230
232
  metadata: object;
231
233
  artistAddress: string;
232
234
  lockExternalTransfer: boolean;
235
+ contractAddress?: string;
233
236
  }
234
- export interface IERC2981RoyaltyRequest extends ContractAddress {
237
+ export interface IERC2981RoyaltyRequest {
235
238
  tokenId?: string;
236
239
  metadata?: object;
237
240
  issuerAddress?: string;
241
+ contractAddress?: string;
238
242
  }
239
243
  export interface IERC2981RoyaltyResponse {
240
244
  royaltyReceiver: string | null;
@@ -265,8 +269,9 @@ declare module '@startbahn/startrail-sdk-js/types' {
265
269
  version?: string;
266
270
  $schemaIntegrity?: string;
267
271
  }
268
- export interface TransferFromWithProvenanceWithMetadataUpdate extends ContractAddress, TransferFromWithProvenance {
272
+ export interface TransferFromWithProvenanceWithMetadataUpdate extends TransferFromWithProvenance {
269
273
  metadata: HistoryMetadata;
274
+ contractAddress?: string;
270
275
  }
271
276
  export interface HTTPHeadersForStartrailLUW {
272
277
  startrailLUWContractAddress: string;
@@ -384,6 +389,7 @@ declare module '@startbahn/startrail-sdk-js/types' {
384
389
  channelNonce: string;
385
390
  }
386
391
  export interface TransferFromWithProvenance extends TransferFromWithProvenanceShared, Pick<HTTPHeadersForStartrailLUW, 'startrailLUWContractAddress'> {
392
+ contractAddress?: string;
387
393
  }
388
394
  export interface Bulk extends Pick<HTTPHeadersForStartrailLUW, 'startrailLUWContractAddress'> {
389
395
  isCompressEnabled: boolean;
@@ -392,11 +398,12 @@ declare module '@startbahn/startrail-sdk-js/types' {
392
398
  data: ApproveSRRByCommitmentShared | CreateSRRForRequest | TransferFromWithProvenanceShared;
393
399
  }[];
394
400
  }
395
- export interface TransferFromWithProvenanceShared extends ContractAddress {
401
+ export interface TransferFromWithProvenanceShared {
396
402
  to: string;
397
403
  tokenId: string;
398
404
  metadata: HistoryMetadata;
399
405
  isIntermediary?: boolean;
406
+ contractAddress?: string;
400
407
  }
401
408
  export interface TTransferFromWithProvenanceDto extends Omit<TransferFromWithProvenanceShared, 'tokenId'> {
402
409
  }
@@ -406,9 +413,10 @@ declare module '@startbahn/startrail-sdk-js/types' {
406
413
  channelNonce?: string;
407
414
  requestData: object;
408
415
  }
409
- export interface UpdateMetadata extends ContractAddress, Pick<HTTPHeadersForStartrailLUW, 'startrailLUWContractAddress'> {
416
+ export interface UpdateMetadata extends Pick<HTTPHeadersForStartrailLUW, 'startrailLUWContractAddress'> {
410
417
  tokenId: string;
411
418
  metadata: object;
419
+ contractAddress?: string;
412
420
  }
413
421
  export type RequestMethod = 'post' | 'put';
414
422
  export interface ResponseOfConvertMetadata {
@@ -690,6 +698,14 @@ declare module '@startbahn/startrail-sdk-js/errorClass' {
690
698
  errorCode: StartrailSdkErrorCodeEnum.METADATA_VALIDATION_FAILED;
691
699
  constructor(err: any);
692
700
  }
701
+ export class JSON_RPC_ERROR extends StartrailSdkErrorBase {
702
+ errorCode: StartrailSdkErrorCodeEnum.JSON_RPC_ERROR | StartrailSdkErrorCodeEnum.CHAINID_MISMATCH;
703
+ constructor(err: {
704
+ message: string;
705
+ code?: number;
706
+ stack?: string;
707
+ });
708
+ }
693
709
  export class Others extends StartrailSdkErrorBase {
694
710
  errorCode: StartrailSdkErrorCodeEnum.OTHERS;
695
711
  constructor(err: any);
@@ -869,6 +885,7 @@ declare module '@startbahn/startrail-sdk-js/constant' {
869
885
  export const ERROR_STATUS_CODE: {
870
886
  USER_REJECTED_REQUEST: number;
871
887
  METADATA_VALIDATION_FAILED: number;
888
+ CHAINID_MISMATCH: number;
872
889
  };
873
890
  export const RPC_URLS: {
874
891
  PROD: string[];
@@ -936,13 +953,21 @@ declare module '@startbahn/startrail-sdk-js/constant' {
936
953
  WALLET_NOT_SUPPORT_FUNCTION = "WALLET_NOT_SUPPORT_FUNCTION",
937
954
  WALLET_RPC_CONNECTION_FAILURE = "WALLET_RPC_CONNECTION_FAILURE",
938
955
  WALLET_USER_REJECT_WALLET_REQUEST = "WALLET_USER_REJECT_WALLET_REQUEST",
939
- METADATA_VALIDATION_FAILED = "METADATA_VALIDATION_FAILED"
956
+ METADATA_VALIDATION_FAILED = "METADATA_VALIDATION_FAILED",
957
+ JSON_RPC_ERROR = "JSON_RPC_ERROR",
958
+ CHAINID_MISMATCH = "CHAINID_MISMATCH"
940
959
  }
941
960
  export type ERROR_FROM_TYPE = 'StartrailSdk';
942
961
  export type ERROR_TYPE = {
943
962
  code: number | string;
944
963
  message: string;
945
964
  statusCode: number;
965
+ data?: {
966
+ cause?: {
967
+ message: string;
968
+ stack: string;
969
+ };
970
+ };
946
971
  };
947
972
  export const TORUS_VERIFIERS: {
948
973
  [key in LoginProvider]: {