Skip to content

Commit

Permalink
fix: spec update (#7)
Browse files Browse the repository at this point in the history
* fix: spec update

* fix: package renamed
  • Loading branch information
tabaktoni authored Jun 4, 2024
1 parent bef7278 commit 5ec8208
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 18 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -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": [
Expand Down
7 changes: 7 additions & 0 deletions src/wallet-api/components.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
11 changes: 11 additions & 0 deletions src/wallet-api/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)';
Expand Down
73 changes: 57 additions & 16 deletions src/wallet-api/methods.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import type {
AddInvokeTransactionResult,
AddStarknetChainParameters,
Address,
ApiVersion,
RequestAccountsParameters,
Signature,
SpecVersion,
Expand All @@ -25,16 +26,21 @@ 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.
* @param params Optional parameters for requesting accounts.
* @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;
};

/**
Expand All @@ -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;
};

Expand All @@ -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;
};

/**
Expand All @@ -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;
};

/**
Expand All @@ -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;
};

/**
Expand All @@ -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;
};

/**
Expand All @@ -118,16 +148,27 @@ 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;
};

/**
* Get the list of supported RPC specification versions.
* @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 = {
Expand Down

0 comments on commit 5ec8208

Please sign in to comment.