@massalabs/wallet-provider 3.1.2-dev.20250116141749 → 3.1.2-dev.20250207102809

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.
@@ -5,6 +5,9 @@ declare global {
5
5
  interface Window {
6
6
  Buffer: typeof Buffer;
7
7
  bearby?: unknown;
8
+ massaWallet?: {
9
+ standalone: boolean;
10
+ };
8
11
  }
9
12
  }
10
13
  export declare enum AvailableCommands {
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";AAAA,gBAAgB;AAChB,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEhC,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,MAAM;QACd,MAAM,EAAE,OAAO,MAAM,CAAC;QACtB,MAAM,CAAC,EAAE,OAAO,CAAC;KAClB;CACF;AAOD,oBAAY,iBAAiB;IAC3B,oBAAoB,kBAAkB;IACtC,qBAAqB,mBAAmB;IACxC,qBAAqB,mBAAmB;IACxC,oBAAoB,mBAAmB;IACvC,kBAAkB,gBAAgB;IAClC,kBAAkB,iBAAiB;IACnC,cAAc,oBAAoB;IAClC,WAAW,iBAAiB;IAC5B,0BAA0B,yBAAyB;IACnD,gBAAgB,uBAAuB;IACvC,eAAe,sBAAsB;IACrC,sBAAsB,6BAA6B;IACnD,aAAa,oBAAoB;CAClC;AAED,cAAc,UAAU,CAAC;AAEzB,OAAO,EAAE,kBAAkB,EAAE,MAAM,mCAAmC,CAAC;AAEvE,OAAO,EAAE,mBAAmB,EAAE,MAAM,oCAAoC,CAAC;AAEzE,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAE1E,cAAc,UAAU,CAAC;AAEzB,OAAO,EACL,uBAAuB,EACvB,oBAAoB,GACrB,MAAM,sCAAsC,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src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CAAA;IACxC,6DAAwC,CAAA;IACxC,4DAAuC,CAAA;IACvC,uDAAkC,CAAA;IAClC,wDAAmC,CAAA;IACnC,uDAAkC,CAAA;IAClC,iDAA4B,CAAA;IAC5B,wEAAmD,CAAA;IACnD,4DAAuC,CAAA;IACvC,0DAAqC,CAAA;IACrC,wEAAmD,CAAA;IACnD,sDAAiC,CAAA;AACnC,CAAC,EAdW,iBAAiB,KAAjB,iBAAiB,QAc5B;AAED,cAAc,UAAU,CAAC;AAEzB,OAAO,EAAE,kBAAkB,EAAE,MAAM,mCAAmC,CAAC;AAEvE,OAAO,EAAE,mBAAmB,EAAE,MAAM,oCAAoC,CAAC;AAEzE,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAE1E,cAAc,UAAU,CAAC;AAEzB,OAAO,EACL,uBAAuB,EACvB,oBAAoB,GACrB,MAAM,sCAAsC,CAAC","sourcesContent":["/** Polyfills */\nimport { Buffer } from 'buffer';\n\ndeclare global {\n interface Window {\n Buffer: typeof Buffer;\n bearby?: unknown;\n }\n}\n\n// Check if we are on browser\nif (typeof window !== 'undefined') {\n window.Buffer = Buffer;\n}\n\nexport enum AvailableCommands {\n ProviderListAccounts = 'LIST_ACCOUNTS',\n ProviderDeleteAccount = 'DELETE_ACCOUNT',\n ProviderImportAccount = 'IMPORT_ACCOUNT',\n ProviderGetNodesUrls = 'GET_NODES_URLS',\n ProviderGetNetwork = 'GET_NETWORK',\n ProviderGetChainId = 'GET_CHAIN_ID',\n AccountBalance = 'ACCOUNT_BALANCE',\n AccountSign = 'ACCOUNT_SIGN',\n ProviderGenerateNewAccount = 'GENERATE_NEW_ACCOUNT',\n AccountSellRolls = 'ACCOUNT_SELL_ROLLS',\n AccountBuyRolls = 'ACCOUNT_BUY_ROLLS',\n AccountSendTransaction = 'ACCOUNT_SEND_TRANSACTION',\n AccountCallSC = 'ACCOUNT_CALL_SC',\n}\n\nexport * from './errors';\n\nexport { MassaStationWallet } from './massaStation/MassaStationWallet';\n\nexport { MassaStationAccount } from './massaStation/MassaStationAccount';\n\nexport { getWallets, getWallet, WalletsListener } from './walletsManager';\n\nexport * from './wallet';\n\nexport {\n isMassaStationAvailable,\n isMassaWalletEnabled,\n} from './massaStation/MassaStationDiscovery';\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,gBAAgB;AAChB,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAYhC,6BAA6B;AAC7B,IAAI,OAAO,MAAM,KAAK,WAAW,EAAE;IACjC,MAAM,CAAC,MAAM,GAAG,MAAM,CAAC;CACxB;AAED,MAAM,CAAN,IAAY,iBAcX;AAdD,WAAY,iBAAiB;IAC3B,2DAAsC,CAAA;IACtC,6DAAwC,CAAA;IACxC,6DAAwC,CAAA;IACxC,4DAAuC,CAAA;IACvC,uDAAkC,CAAA;IAClC,wDAAmC,CAAA;IACnC,uDAAkC,CAAA;IAClC,iDAA4B,CAAA;IAC5B,wEAAmD,CAAA;IACnD,4DAAuC,CAAA;IACvC,0DAAqC,CAAA;IACrC,wEAAmD,CAAA;IACnD,sDAAiC,CAAA;AACnC,CAAC,EAdW,iBAAiB,KAAjB,iBAAiB,QAc5B;AAED,cAAc,UAAU,CAAC;AAEzB,OAAO,EAAE,kBAAkB,EAAE,MAAM,mCAAmC,CAAC;AAEvE,OAAO,EAAE,mBAAmB,EAAE,MAAM,oCAAoC,CAAC;AAEzE,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAE1E,cAAc,UAAU,CAAC;AAEzB,OAAO,EACL,uBAAuB,EACvB,oBAAoB,GACrB,MAAM,sCAAsC,CAAC","sourcesContent":["/** Polyfills */\nimport { Buffer } from 'buffer';\n\ndeclare global {\n interface Window {\n Buffer: typeof Buffer;\n bearby?: unknown;\n massaWallet?: {\n standalone: boolean;\n };\n }\n}\n\n// Check if we are on browser\nif (typeof window !== 'undefined') {\n window.Buffer = Buffer;\n}\n\nexport enum AvailableCommands {\n ProviderListAccounts = 'LIST_ACCOUNTS',\n ProviderDeleteAccount = 'DELETE_ACCOUNT',\n ProviderImportAccount = 'IMPORT_ACCOUNT',\n ProviderGetNodesUrls = 'GET_NODES_URLS',\n ProviderGetNetwork = 'GET_NETWORK',\n ProviderGetChainId = 'GET_CHAIN_ID',\n AccountBalance = 'ACCOUNT_BALANCE',\n AccountSign = 'ACCOUNT_SIGN',\n ProviderGenerateNewAccount = 'GENERATE_NEW_ACCOUNT',\n AccountSellRolls = 'ACCOUNT_SELL_ROLLS',\n AccountBuyRolls = 'ACCOUNT_BUY_ROLLS',\n AccountSendTransaction = 'ACCOUNT_SEND_TRANSACTION',\n AccountCallSC = 'ACCOUNT_CALL_SC',\n}\n\nexport * from './errors';\n\nexport { MassaStationWallet } from './massaStation/MassaStationWallet';\n\nexport { MassaStationAccount } from './massaStation/MassaStationAccount';\n\nexport { getWallets, getWallet, WalletsListener } from './walletsManager';\n\nexport * from './wallet';\n\nexport {\n isMassaStationAvailable,\n isMassaWalletEnabled,\n} from './massaStation/MassaStationDiscovery';\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"MassaStationAccount.d.ts","sourceRoot":"","sources":["../../../src/massaStation/MassaStationAccount.ts"],"names":[],"mappings":"AAoBA,OAAO,EACL,OAAO,EACP,YAAY,EAEZ,cAAc,EACd,WAAW,EAIX,OAAO,EACP,cAAc,EACd,SAAS,EACT,gBAAgB,EAChB,eAAe,EACf,QAAQ,EACR,UAAU,EACV,YAAY,EACZ,UAAU,EACV,WAAW,EACX,aAAa,EAEb,QAAQ,EAGT,MAAM,uBAAuB,CAAC;AAK/B;;;;;;;GAOG;AACH,qBAAa,mBAAoB,YAAW,QAAQ;IAIzC,OAAO,EAAE,MAAM;IACf,WAAW,EAAE,MAAM;IAJ5B,OAAO,CAAC,aAAa,CAA0B;gBAGtC,OAAO,EAAE,MAAM,EACf,WAAW,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OAAO,CAAC,SAAS,CAAC;IAIR,SAAS,CACpB,MAAM,EAAE,MAAM,EACd,IAAI,CAAC,EAAE,gBAAgB,GACtB,OAAO,CAAC,SAAS,CAAC;IAIf,QAAQ,CACZ,EAAE,EAAE,OAAO,GAAG,MAAM,EACpB,MAAM,EAAE,MAAM,EACd,IAAI,CAAC,EAAE,gBAAgB,GACtB,OAAO,CAAC,SAAS,CAAC;IAqBR,MAAM,CAAC,MAAM,EAAE,YAAY,GAAG,OAAO,CAAC,SAAS,CAAC;IAkChD,YAAY,IAAI,OAAO,CAAC,OAAO,CAAC;IAIhC,MAAM,CAAC,MAAM,EAAE,YAAY,GAAG,OAAO,CAAC,UAAU,CAAC;IA2BjD,QAAQ,CAAC,MAAM,EAAE,cAAc,GAAG,OAAO,CAAC,aAAa,CAAC;IA4CrE,SAAS,IAAI,OAAO,CAAC,SAAS,CAAC;IAIlB,kBAAkB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,eAAe,CAAC;IAM1D,SAAS,CAAC,MAAM,EAAE,WAAW,GAAG,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAC;IAM9D,aAAa,IAAI,OAAO,CAAC,cAAc,CAAC;IAMxC,cAAc,CACzB,OAAO,EAAE,MAAM,EACf,MAAM,GAAE,UAAU,GAAG,MAAyB,EAC9C,KAAK,UAAO,GACX,OAAO,CAAC,UAAU,EAAE,CAAC;IAQX,WAAW,CACtB,OAAO,EAAE,MAAM,EACf,IAAI,EAAE,UAAU,EAAE,GAAG,MAAM,EAAE,EAC7B,KAAK,UAAO,GACX,OAAO,CAAC,UAAU,EAAE,CAAC;CASzB"}
@@ -1,5 +1,5 @@
1
1
  import { getRequest, postRequest } from './RequestHandler';
2
- import { MASSA_STATION_URL, MASSA_STATION_ACCOUNTS_URL, } from './MassaStationWallet';
2
+ import { walletApiUrl, MASSA_STATION_URL } from './MassaStationWallet';
3
3
  import { argsToBase64, base64ToByteArray, uint8ArrayToBase64, } from '../utils/base64';
4
4
  import { errorHandler } from '../errors/utils/errorHandler';
5
5
  import { operationType } from '../utils/constants';
@@ -56,7 +56,7 @@ export class MassaStationAccount {
56
56
  message: typeof data === 'string' ? data : new TextDecoder().decode(data),
57
57
  DisplayData: opts?.displayData ?? true,
58
58
  };
59
- const res = await postRequest(`${MASSA_STATION_ACCOUNTS_URL}/${this.accountName}/signMessage`, signData);
59
+ const res = await postRequest(`${walletApiUrl()}/accounts/${this.accountName}/signMessage`, signData);
60
60
  if (res.isError) {
61
61
  throw errorHandler(operationType.Sign, res.error);
62
62
  }
@@ -78,7 +78,7 @@ export class MassaStationAccount {
78
78
  amount: amount.toString(),
79
79
  side: type === operationType.BuyRolls ? 'buy' : 'sell',
80
80
  };
81
- const res = await postRequest(`${MASSA_STATION_ACCOUNTS_URL}/${this.accountName}/rolls`, body);
81
+ const res = await postRequest(`${walletApiUrl()}/accounts/${this.accountName}/rolls`, body);
82
82
  if (res.isError) {
83
83
  throw errorHandler(type, res.error);
84
84
  }
@@ -97,7 +97,7 @@ export class MassaStationAccount {
97
97
  amount: amount.toString(),
98
98
  recipientAddress: to.toString(),
99
99
  };
100
- const res = await postRequest(`${MASSA_STATION_ACCOUNTS_URL}/${this.accountName}/transfer`, body);
100
+ const res = await postRequest(`${walletApiUrl()}/accounts/${this.accountName}/transfer`, body);
101
101
  if (res.isError) {
102
102
  throw errorHandler(operationType.SendTransaction, res.error);
103
103
  }
@@ -1 +1 @@
1
- {"version":3,"file":"MassaStationAccount.js","sourceRoot":"","sources":["../../../src/massaStation/MassaStationAccount.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC3D,OAAO,EACL,iBAAiB,EACjB,0BAA0B,GAC3B,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EACL,YAAY,EACZ,iBAAiB,EACjB,kBAAkB,GACnB,MAAM,iBAAiB,CAAC;AASzB,OAAO,EAAE,YAAY,EAAE,MAAM,8BAA8B,C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,EACf,SAA8B,IAAI,UAAU,EAAE,EAC9C,KAAK,GAAG,IAAI;QAEZ,mGAAmG;QACnG,MAAM,MAAM,GAAG,MAAM,SAAS,EAAE,CAAC;QACjC,MAAM,WAAW,GACf,OAAO,MAAM,KAAK,QAAQ,CAAC,CAAC,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC;QAC3D,OAAO,MAAM,CAAC,gBAAgB,CAAC,OAAO,EAAE,WAAW,EAAE,KAAK,CAAC,CAAC;IAC9D,CAAC;IAEM,KAAK,CAAC,WAAW,CACtB,OAAe,EACf,IAA6B,EAC7B,KAAK,GAAG,IAAI;QAEZ,mGAAmG;QACnG,MAAM,MAAM,GAAG,MAAM,SAAS,EAAE,CAAC;QACjC,MAAM,OAAO,GAAqB,IAAI,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC;YACnD,GAAG;YACH,OAAO;SACR,CAAC,CAAC,CAAC;QACJ,OAAO,MAAM,CAAC,mBAAmB,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;IACpD,CAAC;CACF","sourcesContent":["import { getRequest, postRequest } from './RequestHandler';\nimport {\n MASSA_STATION_URL,\n MASSA_STATION_ACCOUNTS_URL,\n} from './MassaStationWallet';\nimport {\n argsToBase64,\n base64ToByteArray,\n uint8ArrayToBase64,\n} from '../utils/base64';\nimport {\n DeploySCFunctionBody,\n ExecuteFunctionBody,\n MSAccountSignPayload,\n MSAccountSignResp,\n MSBalancesResp,\n MSSendOperationResp,\n} from './types';\nimport { errorHandler } from '../errors/utils/errorHandler';\nimport { operationType } from '../utils/constants';\nimport {\n Address,\n CallSCParams,\n DatastoreEntry,\n DeploySCParams,\n EventFilter,\n formatNodeStatusObject,\n Mas,\n MAX_GAS_CALL,\n Network,\n NodeStatusInfo,\n Operation,\n OperationOptions,\n OperationStatus,\n Provider,\n ReadSCData,\n ReadSCParams,\n SignedData,\n SignOptions,\n SmartContract,\n strToBytes,\n rpcTypes,\n StorageCost,\n formatMas,\n} from '@massalabs/massa-web3';\nimport { getClient, networkInfos } from './utils/network';\nimport { WalletName } from '../wallet';\nimport bs58check from 'bs58check';\n\n/**\n * This module contains the MassaStationAccount class. It is responsible for representing an account in\n * the MassaStation wallet.\n *\n * @remarks\n * This class provides methods to interact with MassaStation account's {@link balance} and to {@link sign} messages.\n *\n */\nexport class MassaStationAccount implements Provider {\n private _providerName = WalletName.MassaWallet;\n\n constructor(\n public address: string,\n public accountName: string,\n ) {}\n\n get providerName(): string {\n return this._providerName;\n }\n\n public async balance(final = false): Promise<bigint> {\n const res = await getRequest<MSBalancesResp>(\n `${MASSA_STATION_URL}massa/addresses?attributes=balance&addresses=${this.address}`,\n );\n\n if (res.isError) throw res.error;\n\n const balances = res.result.addressesAttributes[this.address].balance;\n\n return Mas.fromString(final ? balances.final : balances.pending);\n }\n\n async balanceOf(\n addresses: string[],\n final = false,\n ): Promise<{ address: string; balance: bigint }[]> {\n const queryParams = new URLSearchParams();\n\n queryParams.append('attributes', 'balance');\n addresses.forEach((address) => {\n queryParams.append('addresses', address);\n });\n\n const res = await getRequest<MSBalancesResp>(\n `${MASSA_STATION_URL}massa/addresses?${queryParams.toString()}`,\n );\n\n if (res.isError) throw res.error;\n\n return addresses.map((address) => {\n const balance = res.result.addressesAttributes[address].balance;\n\n return {\n address,\n balance: Mas.fromString(final ? balance.final : balance.pending),\n };\n });\n }\n\n public async sign(\n data: Uint8Array | string,\n opts?: SignOptions,\n ): Promise<SignedData> {\n const signData: MSAccountSignPayload = {\n description: opts?.description ?? '',\n message: typeof data === 'string' ? data : new TextDecoder().decode(data),\n DisplayData: opts?.displayData ?? true,\n };\n\n const res = await postRequest<MSAccountSignResp>(\n `${MASSA_STATION_ACCOUNTS_URL}/${this.accountName}/signMessage`,\n signData,\n );\n\n if (res.isError) {\n throw errorHandler(operationType.Sign, res.error);\n }\n\n // MS Wallet encodes signature in base64... so we need to decode it en re-encode it in base58\n const signature = bs58check.encode(\n await base64ToByteArray(res.result.signature),\n );\n\n return {\n publicKey: res.result.publicKey,\n signature,\n };\n }\n\n private async minimalFee(): Promise<bigint> {\n const client = await getClient();\n return client.getMinimalFee();\n }\n\n private async rollOperation(\n type: operationType.BuyRolls | operationType.SellRolls,\n amount: bigint,\n opts?: OperationOptions,\n ): Promise<Operation> {\n let fee = opts?.fee ?? (await this.minimalFee());\n\n const body = {\n fee: fee.toString(),\n amount: amount.toString(),\n side: type === operationType.BuyRolls ? 'buy' : 'sell',\n };\n\n const res = await postRequest<MSSendOperationResp>(\n `${MASSA_STATION_ACCOUNTS_URL}/${this.accountName}/rolls`,\n body,\n );\n\n if (res.isError) {\n throw errorHandler(type, res.error);\n }\n return new Operation(this, res.result.operationId);\n }\n\n public async buyRolls(\n amount: bigint,\n opts?: OperationOptions,\n ): Promise<Operation> {\n return this.rollOperation(operationType.BuyRolls, amount, opts);\n }\n\n public async sellRolls(\n amount: bigint,\n opts?: OperationOptions,\n ): Promise<Operation> {\n return this.rollOperation(operationType.SellRolls, amount, opts);\n }\n\n async transfer(\n to: Address | string,\n amount: bigint,\n opts?: OperationOptions,\n ): Promise<Operation> {\n const fee = opts?.fee ?? (await this.minimalFee());\n\n const body = {\n fee: fee.toString(),\n amount: amount.toString(),\n recipientAddress: to.toString(),\n };\n\n const res = await postRequest<MSSendOperationResp>(\n `${MASSA_STATION_ACCOUNTS_URL}/${this.accountName}/transfer`,\n body,\n );\n\n if (res.isError) {\n throw errorHandler(operationType.SendTransaction, res.error);\n }\n\n return new Operation(this, res.result.operationId);\n }\n\n public async callSC(params: CallSCParams): Promise<Operation> {\n // convert parameter to base64\n let args = '';\n if (params.parameter instanceof Uint8Array) {\n args = uint8ArrayToBase64(params.parameter);\n } else {\n args = argsToBase64(params.parameter);\n }\n\n let fee = params?.fee ?? (await this.minimalFee());\n\n const body: ExecuteFunctionBody = {\n nickname: this.accountName,\n name: params.func,\n at: params.target,\n args,\n coins: params.coins ? Number(params.coins) : 0,\n fee: fee.toString(),\n // If maxGas is not provided, estimation will be done by MS\n maxGas: params.maxGas ? params.maxGas.toString() : '',\n async: true,\n };\n\n const res = await postRequest<MSSendOperationResp>(\n `${MASSA_STATION_URL}cmd/executeFunction`,\n body,\n );\n\n if (res.isError) {\n throw errorHandler('callSmartContract', res.error);\n }\n return new Operation(this, res.result.operationId);\n }\n\n public async networkInfos(): Promise<Network> {\n return networkInfos();\n }\n\n public async readSC(params: ReadSCParams): Promise<ReadSCData> {\n // Gas amount check\n if (params.maxGas > MAX_GAS_CALL) {\n throw new Error(\n `\n The gas submitted ${params.maxGas.toString()} exceeds the max. allowed block gas of \n ${MAX_GAS_CALL.toString()}\n `,\n );\n }\n\n const client = await getClient();\n\n const fee = params?.fee ?? (await this.minimalFee());\n const caller = params.caller ?? this.address;\n const args = params.parameter ?? new Uint8Array();\n const readOnlyParams = {\n ...params,\n caller,\n fee,\n parameter:\n args instanceof Uint8Array ? args : Uint8Array.from(args.serialize()),\n };\n // This implementation is wrong. We should use massaStation instead of targeting the node directly.\n return client.executeReadOnlyCall(readOnlyParams);\n }\n\n public async deploySC(params: DeploySCParams): Promise<SmartContract> {\n try {\n const args = params.parameter ?? new Uint8Array();\n const parameters = args instanceof Uint8Array ? args : args.serialize();\n const coins = params.coins ?? 0n; // If coins is undefined, some vesions of station will have a panic\n const maxCoins =\n params.maxCoins ??\n StorageCost.smartContract(params.byteCode.length) + coins;\n const fee = params.fee || (await this.minimalFee());\n\n const body: DeploySCFunctionBody = {\n nickname: this.accountName,\n smartContract: uint8ArrayToBase64(params.byteCode),\n maxCoins: maxCoins.toString(), // SmartContract deployment costs\n coins: coins.toString(),\n fee: fee.toString(),\n parameters: uint8ArrayToBase64(parameters),\n description: `${formatMas(\n coins,\n )} $MAS coins allocated to datastore + ${formatMas(\n fee,\n )} $MAS fee for operation`,\n };\n\n const res = await postRequest<MSSendOperationResp>(\n `${MASSA_STATION_URL}cmd/deploySC`,\n body,\n );\n\n const operationId = res.result?.operationId;\n\n if (!operationId) throw new Error('Operation ID not found');\n\n const operation = new Operation(this, operationId);\n const deployedAddress = await operation.getDeployedAddress(\n params.waitFinalExecution,\n );\n\n return new SmartContract(this, deployedAddress);\n } catch (error) {\n throw new Error(`Error during smart contract deployment: ${error}`);\n }\n }\n\n executeSC(): Promise<Operation> {\n throw new Error('Method not implemented.');\n }\n\n public async getOperationStatus(opId: string): Promise<OperationStatus> {\n const client = await getClient();\n // This implementation is wrong. We should use massaStation instead of targeting the node directly.\n return client.getOperationStatus(opId);\n }\n\n public async getEvents(filter: EventFilter): Promise<rpcTypes.OutputEvents> {\n const client = await getClient();\n // This implementation is wrong. We should use massaStation instead of targeting the node directly.\n return client.getEvents(filter);\n }\n\n public async getNodeStatus(): Promise<NodeStatusInfo> {\n const client = await getClient();\n const status = await client.status();\n return formatNodeStatusObject(status);\n }\n\n public async getStorageKeys(\n address: string,\n filter: Uint8Array | string = new Uint8Array(),\n final = true,\n ): Promise<Uint8Array[]> {\n // This implementation is wrong. We should use massaStation instead of targeting the node directly.\n const client = await getClient();\n const filterBytes: Uint8Array =\n typeof filter === 'string' ? strToBytes(filter) : filter;\n return client.getDataStoreKeys(address, filterBytes, final);\n }\n\n public async readStorage(\n address: string,\n keys: Uint8Array[] | string[],\n final = true,\n ): Promise<Uint8Array[]> {\n // This implementation is wrong. We should use massaStation instead of targeting the node directly.\n const client = await getClient();\n const entries: DatastoreEntry[] = keys.map((key) => ({\n key,\n address,\n }));\n return client.getDatastoreEntries(entries, final);\n }\n}\n"]}
1
+ {"version":3,"file":"MassaStationAccount.js","sourceRoot":"","sources":["../../../src/massaStation/MassaStationAccount.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC3D,OAAO,EAAE,YAAY,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AACvE,OAAO,EACL,YAAY,EACZ,iBAAiB,EACjB,kBAAkB,GACnB,MAAM,iBAAiB,CAAC;AASzB,OA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IACxC,CAAC;IAEM,KAAK,CAAC,cAAc,CACzB,OAAe,EACf,SAA8B,IAAI,UAAU,EAAE,EAC9C,KAAK,GAAG,IAAI;QAEZ,mGAAmG;QACnG,MAAM,MAAM,GAAG,MAAM,SAAS,EAAE,CAAC;QACjC,MAAM,WAAW,GACf,OAAO,MAAM,KAAK,QAAQ,CAAC,CAAC,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC;QAC3D,OAAO,MAAM,CAAC,gBAAgB,CAAC,OAAO,EAAE,WAAW,EAAE,KAAK,CAAC,CAAC;IAC9D,CAAC;IAEM,KAAK,CAAC,WAAW,CACtB,OAAe,EACf,IAA6B,EAC7B,KAAK,GAAG,IAAI;QAEZ,mGAAmG;QACnG,MAAM,MAAM,GAAG,MAAM,SAAS,EAAE,CAAC;QACjC,MAAM,OAAO,GAAqB,IAAI,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC;YACnD,GAAG;YACH,OAAO;SACR,CAAC,CAAC,CAAC;QACJ,OAAO,MAAM,CAAC,mBAAmB,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;IACpD,CAAC;CACF","sourcesContent":["import { getRequest, postRequest } from './RequestHandler';\nimport { walletApiUrl, MASSA_STATION_URL } from './MassaStationWallet';\nimport {\n argsToBase64,\n base64ToByteArray,\n uint8ArrayToBase64,\n} from '../utils/base64';\nimport {\n DeploySCFunctionBody,\n ExecuteFunctionBody,\n MSAccountSignPayload,\n MSAccountSignResp,\n MSBalancesResp,\n MSSendOperationResp,\n} from './types';\nimport { errorHandler } from '../errors/utils/errorHandler';\nimport { operationType } from '../utils/constants';\nimport {\n Address,\n CallSCParams,\n DatastoreEntry,\n DeploySCParams,\n EventFilter,\n formatNodeStatusObject,\n Mas,\n MAX_GAS_CALL,\n Network,\n NodeStatusInfo,\n Operation,\n OperationOptions,\n OperationStatus,\n Provider,\n ReadSCData,\n ReadSCParams,\n SignedData,\n SignOptions,\n SmartContract,\n strToBytes,\n rpcTypes,\n StorageCost,\n formatMas,\n} from '@massalabs/massa-web3';\nimport { getClient, networkInfos } from './utils/network';\nimport { WalletName } from '../wallet';\nimport bs58check from 'bs58check';\n\n/**\n * This module contains the MassaStationAccount class. It is responsible for representing an account in\n * the MassaStation wallet.\n *\n * @remarks\n * This class provides methods to interact with MassaStation account's {@link balance} and to {@link sign} messages.\n *\n */\nexport class MassaStationAccount implements Provider {\n private _providerName = WalletName.MassaWallet;\n\n constructor(\n public address: string,\n public accountName: string,\n ) {}\n\n get providerName(): string {\n return this._providerName;\n }\n\n public async balance(final = false): Promise<bigint> {\n const res = await getRequest<MSBalancesResp>(\n `${MASSA_STATION_URL}massa/addresses?attributes=balance&addresses=${this.address}`,\n );\n\n if (res.isError) throw res.error;\n\n const balances = res.result.addressesAttributes[this.address].balance;\n\n return Mas.fromString(final ? balances.final : balances.pending);\n }\n\n async balanceOf(\n addresses: string[],\n final = false,\n ): Promise<{ address: string; balance: bigint }[]> {\n const queryParams = new URLSearchParams();\n\n queryParams.append('attributes', 'balance');\n addresses.forEach((address) => {\n queryParams.append('addresses', address);\n });\n\n const res = await getRequest<MSBalancesResp>(\n `${MASSA_STATION_URL}massa/addresses?${queryParams.toString()}`,\n );\n\n if (res.isError) throw res.error;\n\n return addresses.map((address) => {\n const balance = res.result.addressesAttributes[address].balance;\n\n return {\n address,\n balance: Mas.fromString(final ? balance.final : balance.pending),\n };\n });\n }\n\n public async sign(\n data: Uint8Array | string,\n opts?: SignOptions,\n ): Promise<SignedData> {\n const signData: MSAccountSignPayload = {\n description: opts?.description ?? '',\n message: typeof data === 'string' ? data : new TextDecoder().decode(data),\n DisplayData: opts?.displayData ?? true,\n };\n\n const res = await postRequest<MSAccountSignResp>(\n `${walletApiUrl()}/accounts/${this.accountName}/signMessage`,\n signData,\n );\n\n if (res.isError) {\n throw errorHandler(operationType.Sign, res.error);\n }\n\n // MS Wallet encodes signature in base64... so we need to decode it en re-encode it in base58\n const signature = bs58check.encode(\n await base64ToByteArray(res.result.signature),\n );\n\n return {\n publicKey: res.result.publicKey,\n signature,\n };\n }\n\n private async minimalFee(): Promise<bigint> {\n const client = await getClient();\n return client.getMinimalFee();\n }\n\n private async rollOperation(\n type: operationType.BuyRolls | operationType.SellRolls,\n amount: bigint,\n opts?: OperationOptions,\n ): Promise<Operation> {\n let fee = opts?.fee ?? (await this.minimalFee());\n\n const body = {\n fee: fee.toString(),\n amount: amount.toString(),\n side: type === operationType.BuyRolls ? 'buy' : 'sell',\n };\n\n const res = await postRequest<MSSendOperationResp>(\n `${walletApiUrl()}/accounts/${this.accountName}/rolls`,\n body,\n );\n\n if (res.isError) {\n throw errorHandler(type, res.error);\n }\n return new Operation(this, res.result.operationId);\n }\n\n public async buyRolls(\n amount: bigint,\n opts?: OperationOptions,\n ): Promise<Operation> {\n return this.rollOperation(operationType.BuyRolls, amount, opts);\n }\n\n public async sellRolls(\n amount: bigint,\n opts?: OperationOptions,\n ): Promise<Operation> {\n return this.rollOperation(operationType.SellRolls, amount, opts);\n }\n\n async transfer(\n to: Address | string,\n amount: bigint,\n opts?: OperationOptions,\n ): Promise<Operation> {\n const fee = opts?.fee ?? (await this.minimalFee());\n\n const body = {\n fee: fee.toString(),\n amount: amount.toString(),\n recipientAddress: to.toString(),\n };\n\n const res = await postRequest<MSSendOperationResp>(\n `${walletApiUrl()}/accounts/${this.accountName}/transfer`,\n body,\n );\n\n if (res.isError) {\n throw errorHandler(operationType.SendTransaction, res.error);\n }\n\n return new Operation(this, res.result.operationId);\n }\n\n public async callSC(params: CallSCParams): Promise<Operation> {\n // convert parameter to base64\n let args = '';\n if (params.parameter instanceof Uint8Array) {\n args = uint8ArrayToBase64(params.parameter);\n } else {\n args = argsToBase64(params.parameter);\n }\n\n let fee = params?.fee ?? (await this.minimalFee());\n\n const body: ExecuteFunctionBody = {\n nickname: this.accountName,\n name: params.func,\n at: params.target,\n args,\n coins: params.coins ? Number(params.coins) : 0,\n fee: fee.toString(),\n // If maxGas is not provided, estimation will be done by MS\n maxGas: params.maxGas ? params.maxGas.toString() : '',\n async: true,\n };\n\n const res = await postRequest<MSSendOperationResp>(\n `${MASSA_STATION_URL}cmd/executeFunction`,\n body,\n );\n\n if (res.isError) {\n throw errorHandler('callSmartContract', res.error);\n }\n return new Operation(this, res.result.operationId);\n }\n\n public async networkInfos(): Promise<Network> {\n return networkInfos();\n }\n\n public async readSC(params: ReadSCParams): Promise<ReadSCData> {\n // Gas amount check\n if (params.maxGas > MAX_GAS_CALL) {\n throw new Error(\n `\n The gas submitted ${params.maxGas.toString()} exceeds the max. allowed block gas of \n ${MAX_GAS_CALL.toString()}\n `,\n );\n }\n\n const client = await getClient();\n\n const fee = params?.fee ?? (await this.minimalFee());\n const caller = params.caller ?? this.address;\n const args = params.parameter ?? new Uint8Array();\n const readOnlyParams = {\n ...params,\n caller,\n fee,\n parameter:\n args instanceof Uint8Array ? args : Uint8Array.from(args.serialize()),\n };\n // This implementation is wrong. We should use massaStation instead of targeting the node directly.\n return client.executeReadOnlyCall(readOnlyParams);\n }\n\n public async deploySC(params: DeploySCParams): Promise<SmartContract> {\n try {\n const args = params.parameter ?? new Uint8Array();\n const parameters = args instanceof Uint8Array ? args : args.serialize();\n const coins = params.coins ?? 0n; // If coins is undefined, some vesions of station will have a panic\n const maxCoins =\n params.maxCoins ??\n StorageCost.smartContract(params.byteCode.length) + coins;\n const fee = params.fee || (await this.minimalFee());\n\n const body: DeploySCFunctionBody = {\n nickname: this.accountName,\n smartContract: uint8ArrayToBase64(params.byteCode),\n maxCoins: maxCoins.toString(), // SmartContract deployment costs\n coins: coins.toString(),\n fee: fee.toString(),\n parameters: uint8ArrayToBase64(parameters),\n description: `${formatMas(\n coins,\n )} $MAS coins allocated to datastore + ${formatMas(\n fee,\n )} $MAS fee for operation`,\n };\n\n const res = await postRequest<MSSendOperationResp>(\n `${MASSA_STATION_URL}cmd/deploySC`,\n body,\n );\n\n const operationId = res.result?.operationId;\n\n if (!operationId) throw new Error('Operation ID not found');\n\n const operation = new Operation(this, operationId);\n const deployedAddress = await operation.getDeployedAddress(\n params.waitFinalExecution,\n );\n\n return new SmartContract(this, deployedAddress);\n } catch (error) {\n throw new Error(`Error during smart contract deployment: ${error}`);\n }\n }\n\n executeSC(): Promise<Operation> {\n throw new Error('Method not implemented.');\n }\n\n public async getOperationStatus(opId: string): Promise<OperationStatus> {\n const client = await getClient();\n // This implementation is wrong. We should use massaStation instead of targeting the node directly.\n return client.getOperationStatus(opId);\n }\n\n public async getEvents(filter: EventFilter): Promise<rpcTypes.OutputEvents> {\n const client = await getClient();\n // This implementation is wrong. We should use massaStation instead of targeting the node directly.\n return client.getEvents(filter);\n }\n\n public async getNodeStatus(): Promise<NodeStatusInfo> {\n const client = await getClient();\n const status = await client.status();\n return formatNodeStatusObject(status);\n }\n\n public async getStorageKeys(\n address: string,\n filter: Uint8Array | string = new Uint8Array(),\n final = true,\n ): Promise<Uint8Array[]> {\n // This implementation is wrong. We should use massaStation instead of targeting the node directly.\n const client = await getClient();\n const filterBytes: Uint8Array =\n typeof filter === 'string' ? strToBytes(filter) : filter;\n return client.getDataStoreKeys(address, filterBytes, final);\n }\n\n public async readStorage(\n address: string,\n keys: Uint8Array[] | string[],\n final = true,\n ): Promise<Uint8Array[]> {\n // This implementation is wrong. We should use massaStation instead of targeting the node directly.\n const client = await getClient();\n const entries: DatastoreEntry[] = keys.map((key) => ({\n key,\n address,\n }));\n return client.getDatastoreEntries(entries, final);\n }\n}\n"]}
@@ -9,7 +9,7 @@ export declare const MASSA_STATION_URL = "https://station.massa/";
9
9
  /**
10
10
  * The MassaStation accounts url
11
11
  */
12
- export declare const MASSA_STATION_ACCOUNTS_URL: string;
12
+ export declare function walletApiUrl(): string;
13
13
  /**
14
14
  * This class provides an implementation for communicating with the MassaStation wallet.
15
15
  * @remarks
@@ -1 +1 @@
1
- {"version":3,"file":"MassaStationWallet.d.ts","sourceRoot":"","sources":["../../../src/massaStation/MassaStationWallet.ts"],"names":[],"m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AM,IAAI,CAAA;KAAE,GAAG,SAAS;IAM/D,oBAAoB,CACzB,QAAQ,EAAE,CAAC,OAAO,EAAE,OAAO,KAAK,IAAI,GACnC;QAAE,WAAW,EAAE,MAAM,IAAI,CAAA;KAAE,GAAG,SAAS;IA8B1C;;;OAGG;IACU,OAAO,IAAI,OAAO,CAAC,OAAO,CAAC;IAIxC;;;OAGG;IACU,UAAU,IAAI,OAAO,CAAC,OAAO,CAAC;IAI3C;;;OAGG;IACU,SAAS,IAAI,OAAO,CAAC,OAAO,CAAC;IAI1C;;;OAGG;IACI,OAAO,IAAI,OAAO;CAG1B"}
@@ -12,7 +12,14 @@ export const MASSA_STATION_URL = 'https://station.massa/';
12
12
  /**
13
13
  * The MassaStation accounts url
14
14
  */
15
- export const MASSA_STATION_ACCOUNTS_URL = `${MASSA_STATION_URL}plugin/massa-labs/massa-wallet/api/accounts`;
15
+ export function walletApiUrl() {
16
+ // This is a hack to detect that MS wallet is working in standalone mode
17
+ // dev only usage
18
+ if (typeof window !== 'undefined' && window.massaWallet?.standalone) {
19
+ return `http://localhost:8080/api`;
20
+ }
21
+ return `${MASSA_STATION_URL}plugin/massa-labs/massa-wallet/api`;
22
+ }
16
23
  /**
17
24
  * Events emitted by MassaStation
18
25
  */
@@ -36,7 +43,7 @@ export class MassaStationWallet {
36
43
  return null;
37
44
  }
38
45
  async accounts() {
39
- const res = await getRequest(MASSA_STATION_ACCOUNTS_URL);
46
+ const res = await getRequest(walletApiUrl() + '/accounts');
40
47
  if (res.isError) {
41
48
  throw res.error;
42
49
  }
@@ -49,7 +56,7 @@ export class MassaStationWallet {
49
56
  });
50
57
  }
51
58
  async importAccount(publicKey, privateKey) {
52
- const res = await putRequest(MASSA_STATION_ACCOUNTS_URL, {
59
+ const res = await putRequest(walletApiUrl() + '/accounts', {
53
60
  publicKey,
54
61
  privateKey,
55
62
  });
@@ -59,14 +66,14 @@ export class MassaStationWallet {
59
66
  }
60
67
  async deleteAccount(address) {
61
68
  // get all accounts and find the account to delete
62
- const allAccounts = await getRequest(MASSA_STATION_ACCOUNTS_URL);
69
+ const allAccounts = await getRequest(walletApiUrl() + '/accounts');
63
70
  if (allAccounts.isError)
64
71
  throw allAccounts.error;
65
72
  const accountToDelete = allAccounts.result.find((account) => account.address === address);
66
73
  if (!accountToDelete) {
67
74
  throw new Error('Account not found');
68
75
  }
69
- const res = await deleteRequest(`${MASSA_STATION_ACCOUNTS_URL}/${accountToDelete.nickname}`);
76
+ const res = await deleteRequest(`${walletApiUrl()}/accounts/${accountToDelete.nickname}`);
70
77
  if (res.isError) {
71
78
  throw res.error;
72
79
  }
@@ -84,7 +91,7 @@ export class MassaStationWallet {
84
91
  * @returns a Promise that resolves to the details of the newly generated account.
85
92
  */
86
93
  async generateNewAccount(name) {
87
- const response = await postRequest(MASSA_STATION_ACCOUNTS_URL + '/' + name, {});
94
+ const response = await postRequest(walletApiUrl() + '/accounts/' + name, {});
88
95
  if (response.isError)
89
96
  throw response.error;
90
97
  return new MassaStationAccount(response.result.address, response.result.nickname);
@@ -1 +1 @@
1
- {"version":3,"file":"MassaStationWallet.js","sourceRoot":"","sources":["../../../src/massaStation/MassaStationWallet.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,aAAa,EACb,UAAU,EACV,WAAW,EACX,UAAU,GACX,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAC5D,OAAO,EAAE,yBAAyB,EAA6B,MAAM,SAAS,CAAC;AAC/E,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAG7C,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAC/C,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AACvC,OAAO,EAAE,oBAAoB,EAAE,MAAM,yBAAyB,CAAC;AAE/D;;GAEG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG,wBAAwB,CAAC;AAE1D;;GAEG;AACH,MAAM,CAAC,MA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G,EAAE,EAAE,CAC5D,QAAQ,CAAC,GAAG,CAAC,CACd,CAAC;QAEF,wCAAwC;QACxC,MAAM,UAAU,GAAG,WAAW,CAAC,KAAK,IAAI,EAAE;YACxC,MAAM,OAAO,GAAG,MAAM,IAAI,CAAC,YAAY,EAAE,CAAC;YAC1C,IAAI,CAAC,IAAI,CAAC,cAAc,EAAE;gBACxB,IAAI,CAAC,cAAc,GAAG,OAAO,CAAC;gBAC9B,OAAO;aACR;YACD,IAAI,IAAI,CAAC,cAAc,CAAC,IAAI,KAAK,OAAO,CAAC,IAAI,EAAE;gBAC7C,IAAI,CAAC,cAAc,GAAG,OAAO,CAAC;gBAC9B,IAAI,CAAC,cAAc,CAAC,IAAI,CAAC,6BAA6B,EAAE,OAAO,CAAC,CAAC;aAClE;QACH,CAAC,EAAE,GAAG,CAAC,CAAC;QAER,OAAO;YACL,WAAW,EAAE,GAAG,EAAE;gBAChB,aAAa,CAAC,UAAU,CAAC,CAAC;gBAC1B,IAAI,CAAC,cAAc,CAAC,cAAc,CAChC,6BAA6B;gBAC7B,gEAAgE;gBAChE,GAAG,EAAE,GAAE,CAAC,CACT,CAAC;YACJ,CAAC;SACF,CAAC;IACJ,CAAC;IAED;;;OAGG;IACI,KAAK,CAAC,OAAO;QAClB,OAAO,IAAI,CAAC;IACd,CAAC;IAED;;;OAGG;IACI,KAAK,CAAC,UAAU;QACrB,OAAO,IAAI,CAAC;IACd,CAAC;IAED;;;OAGG;IACI,KAAK,CAAC,SAAS;QACpB,OAAO,IAAI,CAAC;IACd,CAAC;IAED;;;OAGG;IACI,OAAO;QACZ,OAAO,IAAI,CAAC;IACd,CAAC;CACF","sourcesContent":["import {\n deleteRequest,\n getRequest,\n postRequest,\n putRequest,\n} from './RequestHandler';\nimport { MassaStationAccount } from './MassaStationAccount';\nimport { MassaStationAccountStatus, MSAccount, MSAccountsResp } from './types';\nimport { EventEmitter } from 'eventemitter3';\nimport { Wallet } from '../wallet/interface';\nimport { Network } from '@massalabs/massa-web3';\nimport { networkInfos } from './utils/network';\nimport { WalletName } from '../wallet';\nimport { isMassaWalletEnabled } from './MassaStationDiscovery';\n\n/**\n * MassaStation url\n */\nexport const MASSA_STATION_URL = 'https://station.massa/';\n\n/**\n * The MassaStation accounts url\n */\nexport const MASSA_STATION_ACCOUNTS_URL = `${MASSA_STATION_URL}plugin/massa-labs/massa-wallet/api/accounts`;\n\n/**\n * Events emitted by MassaStation\n */\nconst MASSA_STATION_NETWORK_CHANGED = 'MASSA_STATION_NETWORK_CHANGED';\n\n/**\n * This class provides an implementation for communicating with the MassaStation wallet.\n * @remarks\n * This class is used as a proxy to the MassaStation server for exchanging message over https calls.\n */\nexport class MassaStationWallet implements Wallet {\n private walletName = WalletName.MassaWallet;\n\n private eventsListener = new EventEmitter();\n private currentNetwork: Network;\n\n public name(): WalletName {\n return this.walletName;\n }\n\n static async createIfInstalled(): Promise<Wallet | null> {\n if (await isMassaWalletEnabled()) {\n return new MassaStationWallet();\n }\n return null;\n }\n\n public async accounts(): Promise<MassaStationAccount[]> {\n const res = await getRequest<MSAccountsResp>(MASSA_STATION_ACCOUNTS_URL);\n\n if (res.isError) {\n throw res.error;\n }\n return res.result\n .filter((account) => {\n return account.status === MassaStationAccountStatus.OK;\n })\n .map((account) => {\n return new MassaStationAccount(account.address, account.nickname);\n });\n }\n\n public async importAccount(\n publicKey: string,\n privateKey: string,\n ): Promise<void> {\n const res = await putRequest(MASSA_STATION_ACCOUNTS_URL, {\n publicKey,\n privateKey,\n });\n if (res.isError) {\n throw res.error;\n }\n }\n\n public async deleteAccount(address: string): Promise<void> {\n // get all accounts and find the account to delete\n const allAccounts = await getRequest<MSAccountsResp>(\n MASSA_STATION_ACCOUNTS_URL,\n );\n\n if (allAccounts.isError) throw allAccounts.error;\n\n const accountToDelete = allAccounts.result.find(\n (account) => account.address === address,\n );\n\n if (!accountToDelete) {\n throw new Error('Account not found');\n }\n\n const res = await deleteRequest<unknown>(\n `${MASSA_STATION_ACCOUNTS_URL}/${accountToDelete.nickname}`,\n );\n\n if (res.isError) {\n throw res.error;\n }\n }\n\n public async networkInfos(): Promise<Network> {\n return networkInfos();\n }\n\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n public async setRpcUrl(url: string): Promise<void> {\n throw new Error(\n 'setRpcUrl is not yet implemented for the current provider.',\n );\n }\n\n /**\n * This method sends an http call to the MassaStation server to create a new random account.\n *\n * @returns a Promise that resolves to the details of the newly generated account.\n */\n public async generateNewAccount(name: string): Promise<MassaStationAccount> {\n const response = await postRequest<MSAccount>(\n MASSA_STATION_ACCOUNTS_URL + '/' + name,\n {},\n );\n\n if (response.isError) throw response.error;\n\n return new MassaStationAccount(\n response.result.address,\n response.result.nickname,\n );\n }\n\n public listenAccountChanges(): { unsubscribe: () => void } | undefined {\n throw new Error(\n 'listenAccountChanges is not yet implemented for the current provider.',\n );\n }\n\n public listenNetworkChanges(\n callback: (network: Network) => void,\n ): { unsubscribe: () => void } | undefined {\n this.eventsListener.on(MASSA_STATION_NETWORK_CHANGED, (evt) =>\n callback(evt),\n );\n\n // check periodically if network changed\n const intervalId = setInterval(async () => {\n const network = await this.networkInfos();\n if (!this.currentNetwork) {\n this.currentNetwork = network;\n return;\n }\n if (this.currentNetwork.name !== network.name) {\n this.currentNetwork = network;\n this.eventsListener.emit(MASSA_STATION_NETWORK_CHANGED, network);\n }\n }, 500);\n\n return {\n unsubscribe: () => {\n clearInterval(intervalId);\n this.eventsListener.removeListener(\n MASSA_STATION_NETWORK_CHANGED,\n // eslint-disable-next-line @typescript-eslint/no-empty-function\n () => {},\n );\n },\n };\n }\n\n /**\n * Simulates connecting to the station.\n * This method always returns `true` because the station is inherently connected.\n */\n public async connect(): Promise<boolean> {\n return true;\n }\n\n /**\n * Simulates disconnecting from the station.\n * This method always returns `true` because the station cannot be disconnected.\n */\n public async disconnect(): Promise<boolean> {\n return true;\n }\n\n /**\n * Indicates if the station is connected.\n * Always returns `true` because the station is always connected when running.\n */\n public async connected(): Promise<boolean> {\n return true;\n }\n\n /**\n * Indicates if the station is enabled.\n * Always returns `true` because the station is always enabled by default.\n */\n public enabled(): boolean {\n return true;\n }\n}\n"]}
1
+ {"version":3,"file":"MassaStationWallet.js","sourceRoot":"","sources":["../../../src/massaStation/MassaStationWallet.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,aAAa,EACb,UAAU,EACV,WAAW,EACX,UAAU,GACX,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAC5D,OAAO,EAAE,yBAAyB,EAA6B,MAAM,SAAS,CAAC;AAC/E,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAG7C,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAC/C,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AACvC,OAAO,EAAE,oBAAoB,EAAE,MAAM,yBAAyB,CAAC;AAE/D;;GAEG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG,wBAAwB,CAAC;AAE1D;;GAEG;AAEH,MAAM,UAAU,YAAY;IAC1B,wEAAwE;IACxE,iBAAiB;IACjB,IAAI,OAAO,MAAM,KAAK,WAAW,IAAI,MAAM,CAAC,WAAW,EAAE,UAAU,EAAE;QACnE,OAAO,2BAA2B,CAAC;KACpC;IACD,OAAO,GAAG,iBAAiB,oCAAoC,CAAC;AAClE,CAAC;AACD;;GAEG;AACH,MAAM,6BAA6B,GAAG,+BAA+B,CAAC;AAEtE;;;;GAIG;AACH,MAAM,OAAO,kBAAkB;IACrB,UAAU,GAAG,UAAU,CAAC,WAAW,CAAC;IAEpC,cAAc,GAAG,IAAI,YAAY,EAAE,CAAC;IACpC,cAAc,CAAU;IAEzB,IAAI;QACT,OAAO,IAAI,CAAC,UAAU,CAAC;IACzB,CAAC;IAED,MAAM,CAAC,KAAK,CAAC,iBAAiB;QAC5B,IAAI,MAAM,oBAAoB,EAAE,EAAE;YAChC,OAAO,IAAI,kBAAkB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,EAAE;gBAC7C,IAAI,CAAC,cAAc,GAAG,OAAO,CAAC;gBAC9B,IAAI,CAAC,cAAc,CAAC,IAAI,CAAC,6BAA6B,EAAE,OAAO,CAAC,CAAC;aAClE;QACH,CAAC,EAAE,GAAG,CAAC,CAAC;QAER,OAAO;YACL,WAAW,EAAE,GAAG,EAAE;gBAChB,aAAa,CAAC,UAAU,CAAC,CAAC;gBAC1B,IAAI,CAAC,cAAc,CAAC,cAAc,CAChC,6BAA6B;gBAC7B,gEAAgE;gBAChE,GAAG,EAAE,GAAE,CAAC,CACT,CAAC;YACJ,CAAC;SACF,CAAC;IACJ,CAAC;IAED;;;OAGG;IACI,KAAK,CAAC,OAAO;QAClB,OAAO,IAAI,CAAC;IACd,CAAC;IAED;;;OAGG;IACI,KAAK,CAAC,UAAU;QACrB,OAAO,IAAI,CAAC;IACd,CAAC;IAED;;;OAGG;IACI,KAAK,CAAC,SAAS;QACpB,OAAO,IAAI,CAAC;IACd,CAAC;IAED;;;OAGG;IACI,OAAO;QACZ,OAAO,IAAI,CAAC;IACd,CAAC;CACF","sourcesContent":["import {\n deleteRequest,\n getRequest,\n postRequest,\n putRequest,\n} from './RequestHandler';\nimport { MassaStationAccount } from './MassaStationAccount';\nimport { MassaStationAccountStatus, MSAccount, MSAccountsResp } from './types';\nimport { EventEmitter } from 'eventemitter3';\nimport { Wallet } from '../wallet/interface';\nimport { Network } from '@massalabs/massa-web3';\nimport { networkInfos } from './utils/network';\nimport { WalletName } from '../wallet';\nimport { isMassaWalletEnabled } from './MassaStationDiscovery';\n\n/**\n * MassaStation url\n */\nexport const MASSA_STATION_URL = 'https://station.massa/';\n\n/**\n * The MassaStation accounts url\n */\n\nexport function walletApiUrl(): string {\n // This is a hack to detect that MS wallet is working in standalone mode\n // dev only usage\n if (typeof window !== 'undefined' && window.massaWallet?.standalone) {\n return `http://localhost:8080/api`;\n }\n return `${MASSA_STATION_URL}plugin/massa-labs/massa-wallet/api`;\n}\n/**\n * Events emitted by MassaStation\n */\nconst MASSA_STATION_NETWORK_CHANGED = 'MASSA_STATION_NETWORK_CHANGED';\n\n/**\n * This class provides an implementation for communicating with the MassaStation wallet.\n * @remarks\n * This class is used as a proxy to the MassaStation server for exchanging message over https calls.\n */\nexport class MassaStationWallet implements Wallet {\n private walletName = WalletName.MassaWallet;\n\n private eventsListener = new EventEmitter();\n private currentNetwork: Network;\n\n public name(): WalletName {\n return this.walletName;\n }\n\n static async createIfInstalled(): Promise<Wallet | null> {\n if (await isMassaWalletEnabled()) {\n return new MassaStationWallet();\n }\n return null;\n }\n\n public async accounts(): Promise<MassaStationAccount[]> {\n const res = await getRequest<MSAccountsResp>(walletApiUrl() + '/accounts');\n\n if (res.isError) {\n throw res.error;\n }\n return res.result\n .filter((account) => {\n return account.status === MassaStationAccountStatus.OK;\n })\n .map((account) => {\n return new MassaStationAccount(account.address, account.nickname);\n });\n }\n\n public async importAccount(\n publicKey: string,\n privateKey: string,\n ): Promise<void> {\n const res = await putRequest(walletApiUrl() + '/accounts', {\n publicKey,\n privateKey,\n });\n if (res.isError) {\n throw res.error;\n }\n }\n\n public async deleteAccount(address: string): Promise<void> {\n // get all accounts and find the account to delete\n const allAccounts = await getRequest<MSAccountsResp>(\n walletApiUrl() + '/accounts',\n );\n\n if (allAccounts.isError) throw allAccounts.error;\n\n const accountToDelete = allAccounts.result.find(\n (account) => account.address === address,\n );\n\n if (!accountToDelete) {\n throw new Error('Account not found');\n }\n\n const res = await deleteRequest<unknown>(\n `${walletApiUrl()}/accounts/${accountToDelete.nickname}`,\n );\n\n if (res.isError) {\n throw res.error;\n }\n }\n\n public async networkInfos(): Promise<Network> {\n return networkInfos();\n }\n\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n public async setRpcUrl(url: string): Promise<void> {\n throw new Error(\n 'setRpcUrl is not yet implemented for the current provider.',\n );\n }\n\n /**\n * This method sends an http call to the MassaStation server to create a new random account.\n *\n * @returns a Promise that resolves to the details of the newly generated account.\n */\n public async generateNewAccount(name: string): Promise<MassaStationAccount> {\n const response = await postRequest<MSAccount>(\n walletApiUrl() + '/accounts/' + name,\n {},\n );\n\n if (response.isError) throw response.error;\n\n return new MassaStationAccount(\n response.result.address,\n response.result.nickname,\n );\n }\n\n public listenAccountChanges(): { unsubscribe: () => void } | undefined {\n throw new Error(\n 'listenAccountChanges is not yet implemented for the current provider.',\n );\n }\n\n public listenNetworkChanges(\n callback: (network: Network) => void,\n ): { unsubscribe: () => void } | undefined {\n this.eventsListener.on(MASSA_STATION_NETWORK_CHANGED, (evt) =>\n callback(evt),\n );\n\n // check periodically if network changed\n const intervalId = setInterval(async () => {\n const network = await this.networkInfos();\n if (!this.currentNetwork) {\n this.currentNetwork = network;\n return;\n }\n if (this.currentNetwork.name !== network.name) {\n this.currentNetwork = network;\n this.eventsListener.emit(MASSA_STATION_NETWORK_CHANGED, network);\n }\n }, 500);\n\n return {\n unsubscribe: () => {\n clearInterval(intervalId);\n this.eventsListener.removeListener(\n MASSA_STATION_NETWORK_CHANGED,\n // eslint-disable-next-line @typescript-eslint/no-empty-function\n () => {},\n );\n },\n };\n }\n\n /**\n * Simulates connecting to the station.\n * This method always returns `true` because the station is inherently connected.\n */\n public async connect(): Promise<boolean> {\n return true;\n }\n\n /**\n * Simulates disconnecting from the station.\n * This method always returns `true` because the station cannot be disconnected.\n */\n public async disconnect(): Promise<boolean> {\n return true;\n }\n\n /**\n * Indicates if the station is connected.\n * Always returns `true` because the station is always connected when running.\n */\n public async connected(): Promise<boolean> {\n return true;\n }\n\n /**\n * Indicates if the station is enabled.\n * Always returns `true` because the station is always enabled by default.\n */\n public enabled(): boolean {\n return true;\n }\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@massalabs/wallet-provider",
3
- "version": "3.1.2-dev.20250116141749",
3
+ "version": "3.1.2-dev.20250207102809",
4
4
  "description": "massa's wallet provider",
5
5
  "main": "dist/esm/index.js",
6
6
  "module": "dist/esm/index.js",