diff --git a/package.json b/package.json index 9e4d38c..eae5611 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,7 @@ "url": "https://github.com/starkware-libs/starknet-specs.git" }, "scripts": { - "validate_all": "node validate.js api/starknet_api_openrpc.json && node validate.js api/starknet_write_api.json && node validate.js api/starknet_trace_api_openrpc.json" + "validate_all": "node validate.js api/starknet_api_openrpc.json && node validate.js api/starknet_write_api.json && node validate.js api/starknet_trace_api_openrpc.json && node validate.js ./wallet-api/wallet_rpc.json" }, "author": "Lior Schejter", "license": "MIT", @@ -16,4 +16,4 @@ "fs-extra": "10.1.0", "@json-schema-tools/dereferencer": "1.5.4" } -} \ No newline at end of file +} diff --git a/wallet-api/wallet_rpc.json b/wallet-api/wallet_rpc.json new file mode 100644 index 0000000..4e38644 --- /dev/null +++ b/wallet-api/wallet_rpc.json @@ -0,0 +1,860 @@ +{ + "openrpc": "1.0.0-rc1", + "info": { + "version": "0.7.2", + "title": "Starknet Wallet API", + "license": {} + }, + "servers": [], + "methods": [ + { + "name": "wallet_supportedWalletApi", + "summary": "Returns a list of wallet api versions compatible with the wallet. Notice this might be different from Starknet JSON-RPC spec", + "params": [], + "result": { + "name": "result", + "description": "Semver of the wallet api versions supported by the wallet", + "required": true, + "schema": { + "type": "array", + "properties": { + "items": { + "$ref": "#/components/schemas/API_VERSION" + } + } + } + } + }, + { + "name": "wallet_supportedSpecs", + "summary": "Returns a list of rpc spec versions compatible with the wallet", + "params": [], + "result": { + "name": "result", + "description": "Semver of Starknet's JSON-RPC supported by the wallet", + "required": true, + "schema": { + "type": "array", + "properties": { + "items": { + "$ref": "#/components/schemas/SPEC_VERSION" + } + } + } + } + }, + { + "name": "wallet_getPermissions", + "summary": "Get the existing permissions for the Dapp from the wallet", + "params": [ + { + "name": "api_version", + "required": false, + "schema": { + "$ref": "#/components/schemas/API_VERSION" + } + } + ], + "result": { + "name": "result", + "schema": { + "title": "Wallet permissions", + "oneOf": [ + { + "type": "array", + "properties": { + "items": { + "$ref": "#/components/schemas/PERMISSION" + } + } + }, + { + "type": "array", + "title": "Empty array" + } + ], + "required": [] + } + }, + "errors": [ + { + "$ref": "#/components/errors/API_VERSION_NOT_SUPPORTED" + }, + { + "$ref": "#/components/errors/UNKNOWN_ERROR" + } + ] + }, + { + "name": "wallet_requestAccounts", + "summary": "Get the account addresses of the wallet active account, if the Dapp isn't yet permissioned to receive this information, a permission request will be displayed on the wallet UI.", + "params": [ + { + "name": "silent_mode", + "summary": "if true, the wallet will not show the wallet-unlock UI in case of a locked wallet, nor the Dapp-approve UI in case of a non-allowed Dapp", + "required": false, + "schema": { + "type": "boolean" + } + }, + { + "name": "api_version", + "required": false, + "schema": { + "$ref": "#/components/schemas/API_VERSION" + } + } + ], + "result": { + "name": "result", + "description": "The active account of the wallet", + "schema": { + "title": "Wallet Accounts", + "type": "array", + "items": { + "$ref": "#/components/schemas/ADDRESS" + }, + "required": [] + } + }, + "errors": [ + { + "$ref": "#/components/errors/API_VERSION_NOT_SUPPORTED" + }, + { + "$ref": "#/components/errors/UNKNOWN_ERROR" + } + ] + }, + { + "name": "wallet_requestChainId", + "summary": "Request the current Chain Id", + "params": [ + { + "name": "api_version", + "required": false, + "schema": { + "$ref": "#/components/schemas/API_VERSION" + } + } + ], + "result": { + "name": "result", + "description": "The active chainId", + "schema": { + "$ref": "#/components/schemas/CHAIN_ID" + } + }, + "errors": [ + { + "$ref": "#/components/errors/API_VERSION_NOT_SUPPORTED" + }, + { + "$ref": "#/components/errors/UNKNOWN_ERROR" + } + ] + }, + { + "name": "wallet_deploymentData", + "summary": "Request from the current wallet the data required to deploy the account at the current address", + "params": [ + { + "name": "api_version", + "required": false, + "schema": { + "$ref": "#/components/schemas/API_VERSION" + } + } + ], + "result": { + "name": "result", + "schema": { + "$ref": "#/components/schemas/ACCOUNT_DEPLOYMENT_DATA" + } + }, + "errors": [ + { + "$ref": "#/components/errors/ACCOUNT_ALREADY_DEPLOYED" + }, + { + "$ref": "#/components/errors/API_VERSION_NOT_SUPPORTED" + }, + { + "$ref": "#/components/errors/UNKNOWN_ERROR" + } + ] + }, + { + "name": "wallet_switchStarknetChain", + "summary": "Change the current network of the wallet, a permission request will be displayed on the wallet UI.", + "params": [ + { + "name": "chainId", + "required": true, + "schema": { + "$ref": "#/components/schemas/CHAIN_ID" + } + }, + { + "name": "api_version", + "required": false, + "schema": { + "$ref": "#/components/schemas/API_VERSION" + } + } + ], + "result": { + "name": "response", + "summary": "If wallet agrees to change network, return true. If the current network is selected, return true. If network is not added to wallet, return false", + "required": true, + "schema": { + "type": "boolean" + } + }, + "errors": [ + { + "$ref": "#/components/errors/UNLISTED_NETWORK" + }, + { + "$ref": "#/components/errors/USER_REFUSED_OP" + }, + { + "$ref": "#/components/errors/API_VERSION_NOT_SUPPORTED" + }, + { + "$ref": "#/components/errors/UNKNOWN_ERROR" + } + ] + }, + { + "name": "wallet_watchAsset", + "summary": "Add a token in the list of assets displayed by the wallet, the wallet will show an approval UI", + "params": [ + { + "name": "Asset to add", + "description": "Information needed to add asset", + "required": true, + "schema": { + "$ref": "#/components/schemas/ASSET" + } + }, + { + "name": "api_version", + "required": false, + "schema": { + "$ref": "#/components/schemas/API_VERSION" + } + } + ], + "result": { + "name": "response", + "summary": "If adding a token is agreed, or if token is already displayed, return true", + "required": true, + "schema": { + "type": "boolean" + } + }, + "errors": [ + { + "$ref": "#/components/errors/NOT_ERC20" + }, + { + "$ref": "#/components/errors/INVALID_REQUEST_PAYLOAD" + }, + { + "$ref": "#/components/errors/USER_REFUSED_OP" + }, + { + "$ref": "#/components/errors/API_VERSION_NOT_SUPPORTED" + }, + { + "$ref": "#/components/errors/UNKNOWN_ERROR" + } + ] + }, + { + "name": "wallet_addStarknetChain", + "summary": "Add a new network in the list of networks of the wallet, a permission request will be displayed on the wallet UI.", + "params": [ + { + "name": "Starknet Chain to add", + "description": "Information for the chain to add to the wallet", + "required": true, + "schema": { + "$ref": "#/components/schemas/STARKNET_CHAIN" + } + }, + { + "name": "api_version", + "required": false, + "schema": { + "$ref": "#/components/schemas/API_VERSION" + } + } + ], + "result": { + "name": "response", + "summary": "If user agreed, and network added successfully, or if network already listed, return true", + "required": true, + "schema": { + "type": "boolean" + } + }, + "errors": [ + { + "$ref": "#/components/errors/INVALID_REQUEST_PAYLOAD" + }, + { + "$ref": "#/components/errors/USER_REFUSED_OP" + }, + { + "$ref": "#/components/errors/API_VERSION_NOT_SUPPORTED" + }, + { + "$ref": "#/components/errors/UNKNOWN_ERROR" + } + ] + }, + { + "name": "wallet_addInvokeTransaction", + "summary": "Submit a new transaction to be added to the chain", + "params": [ + { + "name": "invoke_transaction", + "description": "A list of calls to invoke in an invoke transaction", + "required": true, + "schema": { + "type": "array", + "items": { + "$ref": "#/components/schemas/INVOKE_CALL" + } + } + }, + { + "name": "api_version", + "required": false, + "schema": { + "$ref": "#/components/schemas/API_VERSION" + } + } + ], + "result": { + "name": "result", + "description": "The result of the transaction submission", + "schema": { + "type": "object", + "properties": { + "transaction_hash": { + "title": "Transaction Hash", + "$ref": "#/components/schemas/PADDED_TXN_HASH" + } + }, + "required": ["transaction_hash"] + } + }, + "errors": [ + { + "$ref": "#/components/errors/INVALID_REQUEST_PAYLOAD" + }, + { + "$ref": "#/components/errors/USER_REFUSED_OP" + }, + { + "$ref": "#/components/errors/API_VERSION_NOT_SUPPORTED" + }, + { + "$ref": "#/components/errors/UNKNOWN_ERROR" + } + ] + }, + { + "name": "wallet_addDeclareTransaction", + "summary": "Submit a declare transaction", + "params": [ + { + "name": "declare_transaction", + "description": "The information needed to declare a new class", + "required": true, + "schema": { + "$ref": "#/components/schemas/DECLARE_TXN" + } + }, + { + "name": "api_version", + "required": false, + "schema": { + "$ref": "#/components/schemas/API_VERSION" + } + } + ], + "result": { + "name": "result", + "description": "The result of the transaction submission", + "schema": { + "type": "object", + "properties": { + "transaction_hash": { + "title": "The hash of the declare transaction", + "$ref": "#/components/schemas/PADDED_TXN_HASH" + }, + "class_hash": { + "title": "The hash of the declared class", + "$ref": "#/components/schemas/PADDED_FELT" + } + }, + "required": ["transaction_hash", "class_hash"] + } + }, + "errors": [ + { + "$ref": "#/components/errors/INVALID_REQUEST_PAYLOAD" + }, + { + "$ref": "#/components/errors/USER_REFUSED_OP" + }, + { + "$ref": "#/components/errors/API_VERSION_NOT_SUPPORTED" + }, + { + "$ref": "#/components/errors/UNKNOWN_ERROR" + } + ] + }, + { + "name": "wallet_signTypedData", + "summary": "Sign typed data using the wallet", + "params": [ + { + "name": "typed_data", + "description": "The typed data to sign", + "required": true, + "schema": { + "$ref": "#/components/schemas/TYPED_DATA" + } + }, + { + "name": "api_version", + "required": false, + "schema": { + "$ref": "#/components/schemas/API_VERSION" + } + } + ], + "result": { + "name": "response", + "summary": "The signature over the typed data", + "required": true, + "schema": { + "$ref": "#/components/schemas/SIGNATURE" + } + }, + "errors": [ + { + "$ref": "#/components/errors/INVALID_REQUEST_PAYLOAD" + }, + { + "$ref": "#/components/errors/USER_REFUSED_OP" + }, + { + "$ref": "#/components/errors/API_VERSION_NOT_SUPPORTED" + }, + { + "$ref": "#/components/errors/UNKNOWN_ERROR" + } + ] + } + ], + "components": { + "contentDescriptors": {}, + "schemas": { + "PADDED_TXN_HASH": { + "title": "Padded Transaction Hash", + "description": "The transaction hash, as assigned in Starknet, padded to 64 hex digits", + "$ref": "#/components/schemas/PADDED_FELT" + }, + "ADDRESS": { + "title": "Address", + "$ref": "#/components/schemas/FELT" + }, + "TOKEN_SYMBOL": { + "title": "ERC20 Token Symbol", + "description": "The symbol of the token", + "type": "string", + "minLength": 1, + "maxLength": 6, + "pattern": "^[A-Za-z0-9]{1,6}$" + }, + "SPEC_VERSION": { + "title": "Starknet Spec Version", + "description": "A Starknet RPC spec version, only two numbers are provided", + "type": "string", + "pattern": "^[0-9]+\\.[0-9]+$" + }, + "API_VERSION": { + "title": "Wallet API version", + "description": "The version of wallet API expected by the request. If not specified, the latest is assumed", + "type": "string", + "pattern": "^[0-9]+\\.[0-9]+$" + }, + "PERMISSION": { + "title": "Wallet permission", + "type": "string", + "enum": ["accounts"], + "description": "Optional wallet permissions" + }, + "ASSET": { + "title": "Starknet Token", + "description": "Details of an onchain Starknet ERC20 token", + "type": "object", + "properties": { + "type": { + "type": "string", + "enum": ["ERC20"] + }, + "options": { + "type": "object", + "properties": { + "address": { + "title": "Token Address", + "$ref": "#/components/schemas/ADDRESS" + }, + "symbol": { + "title": "Token Symbol", + "$ref": "#/components/schemas/TOKEN_SYMBOL" + }, + "decimals": { + "type": "number", + "minimum": 0 + }, + "image": { + "type": "string", + "format": "uri" + }, + "name": { + "type": "string" + } + }, + "required": ["address"] + } + }, + "required": ["type", "options"] + }, + "CHAIN_ID": { + "title": "Chain id", + "description": "Starknet chain id, given in hex representation.", + "type": "string", + "pattern": "^0x[a-fA-F0-9]+$" + }, + "STARKNET_CHAIN_ID": { + "title": "Starknet Chain id", + "description": "Only officially supported Starknet IDs", + "allOf": [ + { + "type": "string", + "enum": ["0x534e5f4d41494e", "0x534e5f474f45524c49", "0x534e5f5345504f4c4941"] + }, + { + "$ref": "#/components/schemas/CHAIN_ID" + } + ] + }, + "ACCOUNT_DEPLOYMENT_DATA": { + "title": "Account Deployment Data", + "description": "Data required to deploy an account at and address", + "type": "object", + "properties": { + "address": { + "title": "Address", + "description": "The expected address to be deployed, used to double check", + "$ref": "#/components/schemas/ADDRESS" + }, + "class_hash": { + "title": "Class hash", + "description": "The hash of the deployed contract's class", + "$ref": "#/components/schemas/FELT" + }, + "salt": { + "title": "Class hash", + "description": "The hash of the deployed contract's class", + "$ref": "#/components/schemas/FELT" + }, + "calldata": { + "type": "array", + "description": "The parameters passed to the constructor", + "title": "Constructor calldata", + "items": { + "$ref": "#/components/schemas/FELT" + } + }, + "sigdata": { + "title": "Signature Data", + "type": "array", + "description": "Optional array of felts to be added to the signature", + "items": { + "$ref": "#/components/schemas/FELT" + } + }, + "version": { + "title": "Contract Version", + "description": "The Cairo version of the contract 0 or 1", + "type": "integer", + "enum": [0, 1] + } + }, + "required": ["address", "class_hash", "salt", "calldata", "version"] + }, + "INVOKE_CALL": { + "title": "Invoke transaction", + "description": "initiates a transaction from a given account", + "type": "object", + "properties": { + "contract_address": { + "title": "The contract address to interact with", + "$ref": "#/components/schemas/ADDRESS" + }, + "entry_point": { + "title": "Contract entry point", + "description": "A string correlating the selector name of the contract, e.g. 'transfer'", + "type": "string" + }, + "calldata": { + "type": "array", + "title": "calldata", + "description": "Calldata to be passed to the entrypoint", + "items": { + "$ref": "#/components/schemas/FELT" + } + } + }, + "required": ["contract_address", "entry_point"] + }, + "DECLARE_TXN": { + "title": "Declare Transaction", + "description": "Declare Contract Transaction", + "type": "object", + "properties": { + "compiled_class_hash": { + "title": "Compiled class hash", + "description": "The hash of the Cairo assembly resulting from the Sierra compilation", + "$ref": "#/components/schemas/FELT" + }, + "class_hash": { + "title": "Class hash", + "description": "The hash of the declared class", + "$ref": "#/components/schemas/FELT" + }, + "contract_class": { + "title": "Contract class", + "description": "The class to be declared", + "$ref": "#/components/schemas/CONTRACT_CLASS" + } + }, + "required": ["compiled_class_hash", "contract_class"] + }, + "STARKNET_CHAIN": { + "title": "Starknet Chain", + "type": "object", + "properties": { + "id": { + "type": "string" + }, + "chain_id": { + "title": "Starknet Chain Id", + "$ref": "#/components/schemas/CHAIN_ID" + }, + "chain_name": { + "type": "string" + }, + "rpc_urls": { + "type": "array", + "items": { + "type": "string", + "format": "uri" + }, + "minItems": 1, + "uniqueItems": true + }, + "block_explorer_url": { + "type": "array", + "items": { + "type": "string", + "format": "uri" + }, + "minItems": 1, + "uniqueItems": true + }, + "native_currency": { + "title": "Native Currency", + "$ref": "#/components/schemas/ASSET" + }, + "icon_urls": { + "type": "array", + "items": { + "type": "string", + "format": "uri" + }, + "minItems": 1, + "uniqueItems": true + } + }, + "required": ["id", "chain_id", "chain_name"] + }, + "STARKNET_MERKLE_TYPE": { + "title": "Starknet Merkle Type", + "type": "object", + "properties": { + "name": { + "type": "string" + }, + "type": { + "type": "string", + "enum": ["merkletree"] + }, + "contains": { + "type": "string" + } + }, + "required": ["name", "type", "contains"] + }, + "STARKNET_ENUM_TYPE": { + "title": "Starknet Enum Type", + "type": "object", + "properties": { + "name": { + "type": "string" + }, + "type": { + "type": "string", + "enum": ["enum"] + }, + "contains": { + "type": "string" + } + }, + "required": ["name", "type", "contains"] + }, + "STARKNET_TYPE": { + "title": "Starknet Type", + "description": "A single type, as part of a struct. The `type` field can be any of the EIP-712 supported types", + "schema": { + "anyOf": [ + { + "type": "object", + "properties": { + "name": { "type": "string" }, + "type": { "type": "string" } + }, + "required": ["name", "type"] + }, + { + "$ref": "#/components/schemas/STARKNET_MERKLE_TYPE" + }, + { + "$ref": "#/components/schemas/STARKNET_ENUM_TYPE" + } + ] + } + }, + "TYPED_DATA": { + "title": "Typed Data", + "type": "object", + "properties": { + "types": { + "description": "Defines the types of the typed data object", + "type": "object", + "additionalProperties": { + "type": "array", + "itmes": { + "$ref": "#/components/schemas/STARKNET_TYPE" + } + } + }, + "primaryType": { + "type": "string", + "description": "primaryType represents the top-level type of the object in the message" + }, + "domain": { + "description": "The EIP712 domain struct. Any of these fields are optional, but it must contain at least one field", + "$ref": "#/components/schemas/STARKNET_DOMAIN" + }, + "message": { + "type": "object", + "description": "The message to be signed" + } + }, + "required": ["types", "primaryType", "domain", "message"] + }, + "STARKNET_DOMAIN": { + "title": "Starknet Domain", + "type": "object", + "minProperties": 1, + "properties": { + "name": { "type": "string" }, + "version": { "type": "string" }, + "chainId": { + "anyOf": [{ "type": "string" }, { "type": "number" }] + }, + "revision": { + "oneOf": [ + { + "type": "string", + "enum": ["2"] + }, + { + "type": "number", + "enum": [0, 1] + } + ] + } + } + }, + "PADDED_FELT": { + "type": "string", + "title": "Padded felt", + "description": "A padded felt represented as 62 hex digits, 3 bits, and 5 leading zero bits.", + "pattern": "^0x(0[0-8]{1}[a-fA-F0-9]{62}$)" + }, + "CONTRACT_CLASS": { + "$ref": "./api/starknet_api_openrpc.json#/components/schemas/CONTRACT_CLASS" + }, + "SIGNATURE": { + "$ref": "./api/starknet_api_openrpc.json#/components/schemas/SIGNATURE" + }, + "FELT": { + "$ref": "./api/starknet_api_openrpc.json#/components/schemas/FELT" + } + }, + "errors": { + "NOT_ERC20": { + "code": 111, + "message": "An error occurred (NOT_ERC20)" + }, + "UNLISTED_NETWORK": { + "code": 112, + "message": "An error occurred (UNLISTED_NETWORK)" + }, + "USER_REFUSED_OP": { + "code": 113, + "message": "An error occurred (USER_REFUSED_OP)" + }, + "INVALID_REQUEST_PAYLOAD": { + "code": 114, + "message": "An error occurred (INVALID_REQUEST_PAYLOAD)" + }, + "ACCOUNT_ALREADY_DEPLOYED": { + "code": 115, + "message": "An error occurred (ACCOUNT_ALREADY_DEPLOYED)" + }, + "API_VERSION_NOT_SUPPORTED": { + "code": 162, + "message": "An error occurred (API_VERSION_NOT_SUPPORTED)", + "data": "string" + }, + "UNKNOWN_ERROR": { + "code": 163, + "message": "An error occurred (UNKNOWN_ERROR)", + "data": "string" + } + } + } +}