diff --git a/package.json b/package.json index 5476ddf..99fb9a2 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { - "name": "starknet-types", - "version": "0.7.2", + "name": "@starknet-io/types-js", + "version": "0.7.3", "description": "Shared TypeScript definitions for Starknet projects", "homepage": "https://github.com/starknet-io/types-js", "keywords": [ diff --git a/src/wallet-api/components.ts b/src/wallet-api/components.ts index a9de056..3ffe27c 100644 --- a/src/wallet-api/components.ts +++ b/src/wallet-api/components.ts @@ -140,3 +140,10 @@ export interface AccountDeploymentData { sigdata?: FELT[]; // An optional array of felts to be added in the signature version: 0 | 1; // Cairo version (an integer) } + +/** + * The version of wallet API the request expecting. If not specified, the latest is assumed + */ +export interface ApiVersion { + api_version?: string; +} diff --git a/src/wallet-api/errors.ts b/src/wallet-api/errors.ts index 7d90373..711fa92 100644 --- a/src/wallet-api/errors.ts +++ b/src/wallet-api/errors.ts @@ -18,6 +18,17 @@ export interface INVALID_REQUEST_PAYLOAD { message: 'An error occurred (INVALID_REQUEST_PAYLOAD)'; } +export interface ACCOUNT_ALREADY_DEPLOYED { + code: 115; + message: 'An error occurred (ACCOUNT_ALREADY_DEPLOYED)'; +} + +export interface API_VERSION_NOT_SUPPORTED { + code: 162; + message: 'An error occurred (API_VERSION_NOT_SUPPORTED)'; + data: 'string'; +} + export interface UNKNOWN_ERROR { code: 163; message: 'An error occurred (UNKNOWN_ERROR)'; diff --git a/src/wallet-api/methods.ts b/src/wallet-api/methods.ts index f571ba7..01e7381 100644 --- a/src/wallet-api/methods.ts +++ b/src/wallet-api/methods.ts @@ -9,6 +9,7 @@ import type { AddInvokeTransactionResult, AddStarknetChainParameters, Address, + ApiVersion, RequestAccountsParameters, Signature, SpecVersion, @@ -25,7 +26,11 @@ export interface RpcTypeToMessageMap { * Get permissions from the wallet. * @returns An array of permissions. */ - wallet_getPermissions: { params?: never; result: Permission[] | [] }; + wallet_getPermissions: { + params?: ApiVersion; + result: Permission[] | []; + errors: Errors.API_VERSION_NOT_SUPPORTED | Errors.UNKNOWN_ERROR; + }; /** * Request active accounts from the wallet. @@ -33,8 +38,9 @@ export interface RpcTypeToMessageMap { * @returns An array of account addresses as strings. */ wallet_requestAccounts: { - params?: RequestAccountsParameters; + params?: RequestAccountsParameters & ApiVersion; result: Address[]; + errors: Errors.API_VERSION_NOT_SUPPORTED | Errors.UNKNOWN_ERROR; }; /** @@ -43,12 +49,13 @@ export interface RpcTypeToMessageMap { * @returns A boolean indicating if the operation was successful. */ wallet_watchAsset: { - params: WatchAssetParameters; + params: WatchAssetParameters & ApiVersion; result: boolean; errors: | Errors.NOT_ERC20 | Errors.INVALID_REQUEST_PAYLOAD | Errors.USER_REFUSED_OP + | Errors.API_VERSION_NOT_SUPPORTED | Errors.UNKNOWN_ERROR; }; @@ -58,9 +65,13 @@ export interface RpcTypeToMessageMap { * @returns A boolean indicating if the operation was successful. */ wallet_addStarknetChain: { - params: AddStarknetChainParameters; + params: AddStarknetChainParameters & ApiVersion; result: boolean; - errors: Errors.INVALID_REQUEST_PAYLOAD | Errors.USER_REFUSED_OP | Errors.UNKNOWN_ERROR; + errors: + | Errors.INVALID_REQUEST_PAYLOAD + | Errors.USER_REFUSED_OP + | Errors.API_VERSION_NOT_SUPPORTED + | Errors.UNKNOWN_ERROR; }; /** @@ -69,25 +80,36 @@ export interface RpcTypeToMessageMap { * @returns A boolean indicating if the operation was successful. */ wallet_switchStarknetChain: { - params: SwitchStarknetChainParameters; + params: SwitchStarknetChainParameters & ApiVersion; result: boolean; - errors: Errors.UNLISTED_NETWORK | Errors.USER_REFUSED_OP | Errors.UNKNOWN_ERROR; + errors: + | Errors.UNLISTED_NETWORK + | Errors.USER_REFUSED_OP + | Errors.API_VERSION_NOT_SUPPORTED + | Errors.UNKNOWN_ERROR; }; /** * Request the current chain ID from the wallet. * @returns The current Starknet chain ID. */ - wallet_requestChainId: { params?: never; result: ChainId }; + wallet_requestChainId: { + params?: ApiVersion; + result: ChainId; + errors: Errors.API_VERSION_NOT_SUPPORTED | Errors.UNKNOWN_ERROR; + }; /** * Get deployment data for a contract. * @returns The deployment data result. */ wallet_deploymentData: { - params?: never; + params?: ApiVersion; result: AccountDeploymentData; - errors: Errors.USER_REFUSED_OP | Errors.UNKNOWN_ERROR; + errors: + | Errors.ACCOUNT_ALREADY_DEPLOYED + | Errors.API_VERSION_NOT_SUPPORTED + | Errors.UNKNOWN_ERROR; }; /** @@ -96,9 +118,13 @@ export interface RpcTypeToMessageMap { * @returns The result of adding the invoke transaction. */ wallet_addInvokeTransaction: { - params: AddInvokeTransactionParameters; + params: AddInvokeTransactionParameters & ApiVersion; result: AddInvokeTransactionResult; - errors: Errors.INVALID_REQUEST_PAYLOAD | Errors.USER_REFUSED_OP | Errors.UNKNOWN_ERROR; + errors: + | Errors.INVALID_REQUEST_PAYLOAD + | Errors.USER_REFUSED_OP + | Errors.API_VERSION_NOT_SUPPORTED + | Errors.UNKNOWN_ERROR; }; /** @@ -107,9 +133,13 @@ export interface RpcTypeToMessageMap { * @returns The result of adding the declare transaction. */ wallet_addDeclareTransaction: { - params: AddDeclareTransactionParameters; + params: AddDeclareTransactionParameters & ApiVersion; result: AddDeclareTransactionResult; - errors: Errors.INVALID_REQUEST_PAYLOAD | Errors.USER_REFUSED_OP | Errors.UNKNOWN_ERROR; + errors: + | Errors.INVALID_REQUEST_PAYLOAD + | Errors.USER_REFUSED_OP + | Errors.API_VERSION_NOT_SUPPORTED + | Errors.UNKNOWN_ERROR; }; /** @@ -118,9 +148,13 @@ export interface RpcTypeToMessageMap { * @returns An array of signatures as strings. */ wallet_signTypedData: { - params: TypedData; + params: TypedData & ApiVersion; result: Signature; - errors: Errors.INVALID_REQUEST_PAYLOAD | Errors.USER_REFUSED_OP | Errors.UNKNOWN_ERROR; + errors: + | Errors.INVALID_REQUEST_PAYLOAD + | Errors.USER_REFUSED_OP + | Errors.API_VERSION_NOT_SUPPORTED + | Errors.UNKNOWN_ERROR; }; /** @@ -128,6 +162,13 @@ export interface RpcTypeToMessageMap { * @returns An array of supported specification strings. */ wallet_supportedSpecs: { params?: never; result: SpecVersion[] }; + + /** + * Returns a list of wallet api versions compatible with the wallet. + * Notice this might be different from Starknet JSON-RPC spec + * @returns An array of supported wallet api versions. + */ + wallet_supportedWalletApi: { params?: never; result: ApiVersion[] }; } export type RpcMessage = {