@massalabs/wallet-provider 1.2.1-dev.20230810130757 → 1.2.1-dev.20230810193207

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/bundle.js CHANGED
@@ -6602,7 +6602,6 @@ const bearby_js_1 = __webpack_require__(/*! @hicaru/bearby.js */ "./node_modules
6602
6602
  const RequestHandler_1 = __webpack_require__(/*! ../massaStation/RequestHandler */ "./src/massaStation/RequestHandler.ts");
6603
6603
  const jsonRpcMethods_1 = __webpack_require__(/*! ./jsonRpcMethods */ "./src/bearbyWallet/jsonRpcMethods.ts");
6604
6604
  const axios_1 = __webpack_require__(/*! axios */ "./node_modules/axios/index.js");
6605
- const BearbyProvider_1 = __webpack_require__(/*! ./BearbyProvider */ "./src/bearbyWallet/BearbyProvider.ts");
6606
6605
  const Xbqcrypto_1 = __webpack_require__(/*! ./Xbqcrypto */ "./src/bearbyWallet/Xbqcrypto.ts");
6607
6606
  /**
6608
6607
  * The maximum allowed gas for a read operation
@@ -6653,8 +6652,17 @@ class BearbyAccount {
6653
6652
  providerName() {
6654
6653
  return this._providerName;
6655
6654
  }
6655
+ async connect() {
6656
+ try {
6657
+ await bearby_js_1.web3.wallet.connect();
6658
+ }
6659
+ catch (ex) {
6660
+ console.log('Bearby connection: ', ex);
6661
+ }
6662
+ }
6656
6663
  // needs testing
6657
6664
  async balance() {
6665
+ await this.connect();
6658
6666
  // Not available on bearby. we have to manually call the api
6659
6667
  const body = {
6660
6668
  jsonrpc: '2.0',
@@ -6673,6 +6681,7 @@ class BearbyAccount {
6673
6681
  }
6674
6682
  // need testing
6675
6683
  async sign(data) {
6684
+ await this.connect();
6676
6685
  const encoder = new TextEncoder();
6677
6686
  if (typeof data === 'string') {
6678
6687
  const signature = await bearby_js_1.web3.wallet.signMessage(data);
@@ -6689,6 +6698,7 @@ class BearbyAccount {
6689
6698
  }
6690
6699
  // need testing
6691
6700
  async buyRolls(amount, fee) {
6701
+ await this.connect();
6692
6702
  const signedTx = await bearby_js_1.web3.wallet.signTransaction({
6693
6703
  type: OperationsType.RollBuy,
6694
6704
  amount: amount.toString(),
@@ -6701,6 +6711,7 @@ class BearbyAccount {
6701
6711
  }
6702
6712
  // need testing
6703
6713
  async sellRolls(amount, fee) {
6714
+ await this.connect();
6704
6715
  const signedTx = await bearby_js_1.web3.wallet.signTransaction({
6705
6716
  type: OperationsType.RollSell,
6706
6717
  amount: amount.toString(),
@@ -6712,6 +6723,7 @@ class BearbyAccount {
6712
6723
  throw new Error('Method not implemented.');
6713
6724
  }
6714
6725
  async sendTransaction(amount, recipientAddress, fee) {
6726
+ await this.connect();
6715
6727
  const signedTx = await bearby_js_1.web3.wallet.signTransaction({
6716
6728
  type: OperationsType.Payment,
6717
6729
  amount: amount.toString(),
@@ -6719,12 +6731,12 @@ class BearbyAccount {
6719
6731
  fee: fee.toString(),
6720
6732
  payload: '', // TODO: check how do we have to set it
6721
6733
  });
6722
- console.log(signedTx);
6723
6734
  return {
6724
6735
  operationId: '00',
6725
6736
  };
6726
6737
  }
6727
6738
  async callSC(contractAddress, functionName, parameter, amount, fee, maxGas, nonPersistentExecution = false) {
6739
+ await this.connect();
6728
6740
  if (nonPersistentExecution) {
6729
6741
  return this.nonPersistentCallSC(contractAddress, functionName, parameter, amount, fee, maxGas);
6730
6742
  }
@@ -6742,69 +6754,19 @@ class BearbyAccount {
6742
6754
  });
6743
6755
  }
6744
6756
  catch (ex) {
6745
- throw new Error(
6746
- /* eslint-disable-next-line max-len */
6747
- 'Bearby wallet does not support Uint8Array, serializable and serializableObjectArray. To use them switch to MassaStation');
6757
+ throw new Error(`
6758
+ Bearby wallet does not support Uint8Array, serializable, and serializableObjectArray.
6759
+ To use them switch to MassaStation`);
6748
6760
  }
6749
- return await bearby_js_1.web3.contract.call({
6761
+ const operationId = await bearby_js_1.web3.contract.call({
6750
6762
  maxGas: Number(maxGas),
6751
6763
  coins: Number(amount),
6752
6764
  fee: Number(fee),
6753
6765
  targetAddress: contractAddress,
6754
6766
  functionName: functionName,
6755
- parameters: params,
6767
+ parameters: params.slice(1),
6756
6768
  });
6757
- // // convert parameter to an array of numbers
6758
- // let argumentArray: Array<number> = [];
6759
- // if (parameter instanceof Uint8Array) {
6760
- // argumentArray = Array.from(parameter);
6761
- // } else {
6762
- // argumentArray = Array.from(parameter.serialize());
6763
- // }
6764
- // const callData = {
6765
- // fee: fee,
6766
- // maxGas: maxGas,
6767
- // coins: amount,
6768
- // targetAddress: contractAddress,
6769
- // functionName: functionName,
6770
- // parameter: argumentArray,
6771
- // } as ICallData;
6772
- // // get next period info to set the expiry period
6773
- // const nodeStatusInfo: NodeStatus = await this.getNodeStatus();
6774
- // // 5 is the default value used in massa-web3 for expiry period
6775
- // const expiryPeriod: number = nodeStatusInfo.next_slot.period + 5;
6776
- // // bytes compaction
6777
- // const bytesCompact: Buffer = compactBytesForOperation(
6778
- // callData,
6779
- // OperationTypeId.CallSC,
6780
- // expiryPeriod,
6781
- // );
6782
- // // We need the public key but bearby doesn't allow us to get it directly.
6783
- // // We have to sign a message and get the public key from the signature
6784
- // const pubKey = (await this.sign('nothing')).publicKey;
6785
- // // sign payload
6786
- // const bytesPublicKey: Uint8Array = getBytesPublicKey(pubKey);
6787
- // // get the signature and encode it to base58
6788
- // const signatureUInt8Array = (
6789
- // await this.sign(Buffer.concat([bytesPublicKey, bytesCompact]))
6790
- // ).signature;
6791
- // const signature = base58Encode(signatureUInt8Array);
6792
- // // request data
6793
- // const data = {
6794
- // serialized_content: Array.prototype.slice.call(bytesCompact),
6795
- // creator_public_key: pubKey,
6796
- // signature: signature,
6797
- // };
6798
- // // returns operation ids
6799
- // let opIds: Array<string> = [];
6800
- // const jsonRpcRequestMethod = JSON_RPC_REQUEST_METHOD.SEND_OPERATIONS;
6801
- // opIds = await this.sendJsonRPCRequest(jsonRpcRequestMethod, [[data]]);
6802
- // if (opIds.length <= 0) {
6803
- // throw new Error(
6804
- // `Call smart contract operation bad response. No results array in json rpc response. Inspect smart contract`,
6805
- // );
6806
- // }
6807
- // return opIds[0];
6769
+ return { operationId };
6808
6770
  }
6809
6771
  /**
6810
6772
  * Retrieves the node's status.
@@ -6886,54 +6848,6 @@ class BearbyAccount {
6886
6848
  error: null,
6887
6849
  };
6888
6850
  }
6889
- /**
6890
- * Find provider for a concrete rpc method
6891
- *
6892
- * @remarks
6893
- * This method chooses the provider to use for a given rpc method.
6894
- * - If the rpc method is about getting or sending data to the blockchain,
6895
- * it will choose a public provider.
6896
- * - If the rpc method is meant to be used by the node itself, it will choose a private provider.
6897
- * - An error is thrown if no provider is found for the rpc method.
6898
- *
6899
- * @param requestMethod - The rpc method to find the provider for.
6900
- *
6901
- * @returns The provider for the rpc method.
6902
- */
6903
- getProviderForRpcMethod(requestMethod) {
6904
- switch (requestMethod) {
6905
- case jsonRpcMethods_1.JSON_RPC_REQUEST_METHOD.GET_ADDRESSES:
6906
- case jsonRpcMethods_1.JSON_RPC_REQUEST_METHOD.GET_STATUS:
6907
- case jsonRpcMethods_1.JSON_RPC_REQUEST_METHOD.SEND_OPERATIONS:
6908
- case jsonRpcMethods_1.JSON_RPC_REQUEST_METHOD.GET_OPERATIONS:
6909
- case jsonRpcMethods_1.JSON_RPC_REQUEST_METHOD.GET_BLOCKS:
6910
- case jsonRpcMethods_1.JSON_RPC_REQUEST_METHOD.GET_ENDORSEMENTS:
6911
- case jsonRpcMethods_1.JSON_RPC_REQUEST_METHOD.GET_CLIQUES:
6912
- case jsonRpcMethods_1.JSON_RPC_REQUEST_METHOD.GET_STAKERS:
6913
- case jsonRpcMethods_1.JSON_RPC_REQUEST_METHOD.GET_FILTERED_SC_OUTPUT_EVENT:
6914
- case jsonRpcMethods_1.JSON_RPC_REQUEST_METHOD.EXECUTE_READ_ONLY_BYTECODE:
6915
- case jsonRpcMethods_1.JSON_RPC_REQUEST_METHOD.EXECUTE_READ_ONLY_CALL:
6916
- case jsonRpcMethods_1.JSON_RPC_REQUEST_METHOD.GET_DATASTORE_ENTRIES:
6917
- case jsonRpcMethods_1.JSON_RPC_REQUEST_METHOD.GET_BLOCKCLIQUE_BLOCK_BY_SLOT:
6918
- case jsonRpcMethods_1.JSON_RPC_REQUEST_METHOD.GET_GRAPH_INTERVAL: {
6919
- return new BearbyProvider_1.BearbyProvider('Bearby');
6920
- }
6921
- case jsonRpcMethods_1.JSON_RPC_REQUEST_METHOD.STOP_NODE:
6922
- case jsonRpcMethods_1.JSON_RPC_REQUEST_METHOD.NODE_BAN_BY_ID:
6923
- case jsonRpcMethods_1.JSON_RPC_REQUEST_METHOD.NODE_BAN_BY_IP:
6924
- case jsonRpcMethods_1.JSON_RPC_REQUEST_METHOD.NODE_UNBAN_BY_ID:
6925
- case jsonRpcMethods_1.JSON_RPC_REQUEST_METHOD.NODE_UNBAN_BY_IP:
6926
- case jsonRpcMethods_1.JSON_RPC_REQUEST_METHOD.GET_STAKING_ADDRESSES:
6927
- case jsonRpcMethods_1.JSON_RPC_REQUEST_METHOD.REMOVE_STAKING_ADDRESSES:
6928
- case jsonRpcMethods_1.JSON_RPC_REQUEST_METHOD.ADD_STAKING_PRIVATE_KEYS:
6929
- case jsonRpcMethods_1.JSON_RPC_REQUEST_METHOD.NODE_SIGN_MESSAGE:
6930
- case jsonRpcMethods_1.JSON_RPC_REQUEST_METHOD.NODE_REMOVE_FROM_WHITELIST: {
6931
- return new BearbyProvider_1.BearbyProvider('Bearby');
6932
- }
6933
- default:
6934
- throw new Error(`Unknown Json rpc method: ${requestMethod}`);
6935
- }
6936
- }
6937
6851
  async nonPersistentCallSC(contractAddress, functionName, parameter, amount, fee, maxGas) {
6938
6852
  // not clean but bearby doesn't allow us to get its node urls
6939
6853
  const node = exports.PUBLIC_NODE_RPC;
@@ -7560,10 +7474,9 @@ async function providers(retry = true, timeout = 3000, pollInterval = 500) {
7560
7474
  return [];
7561
7475
  }
7562
7476
  await Connector_1.connector.startMassaStationDiscovery();
7563
- // Look for Bearby
7564
- let p;
7565
- if ((0, BearbyConnect_1.detectBearby)()) {
7566
- p = new BearbyProvider_1.BearbyProvider('Bearby');
7477
+ let bearby;
7478
+ if (await (0, BearbyConnect_1.detectBearby)()) {
7479
+ bearby = new BearbyProvider_1.BearbyProvider('Bearby');
7567
7480
  }
7568
7481
  return new Promise((resolve) => {
7569
7482
  let provider = [];
@@ -7578,8 +7491,8 @@ async function providers(retry = true, timeout = 3000, pollInterval = 500) {
7578
7491
  }
7579
7492
  }
7580
7493
  // Look for Bearby
7581
- if (p) {
7582
- provider.push(p);
7494
+ if (bearby) {
7495
+ provider.push(bearby);
7583
7496
  }
7584
7497
  // If no providers are available, wait and try again
7585
7498
  if (retry && provider.length === 0) {
@@ -9700,7 +9613,7 @@ const web3 = main();
9700
9613
  /******/ // Load entry module and return exports
9701
9614
  /******/ // This entry module is referenced by other modules so it can't be inlined
9702
9615
  /******/ var __webpack_exports__ = __webpack_require__("./src/index.ts");
9703
- /******/ window.massa = __webpack_exports__;
9616
+ /******/ window.massaWallet = __webpack_exports__;
9704
9617
  /******/
9705
9618
  /******/ })()
9706
9619
  ;