ARC-1193: Aleo Provider Javascript API #30
mellowcroc
started this conversation in
ARCs
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
arc: 1193
title: Aleo Provider Javascript API
authors: Jin Seok Park [email protected], Seungju Lee [email protected]
discussion: #30
topic: Application
status: Draft
created: 1/9/2023
Abstract
Currently, there is no standard way for Dapps to communicate with Wallet apps, which means that Dapps need to
create multiple adapters to communicate with different Wallet apps. This problem will get exponentially worse
as the number of Dapps and Wallets increase.
By formalizing Provider APIs that Wallet apps can expose to Dapps, we expect to increase wallet interoperability
and facilitate onboarding of existing Wallet apps onto the Aleo Dapp ecosystem.
Specification
Definitions
Connectivity
The Provider is said to be “connected” when it can service RPC requests to at least one chain
The Provider is said to be "disconnected" when it cannot service RPC requests to any chain at all.
API
The Provider MUST implement and expose the API defined in this section. All API entities MUST adhere to the types and interfaces defined in this section.
request
The Provider MUST identify the requested RPC method by the value of
RequestArguments.method
.If the requested RPC method takes any parameters, the Provider MUST accept them as the value of
RequestArguments.params
.RPC requests MUST be handled such that the returned Promise either resolves with a value per the requested RPC method's specification, or rejects with an error.
If resolved, the Promise MUST resolve with a result per the RPC method's specification. The Promise MUST NOT resolve with any RPC protocol-specific response objects, unless the RPC method's return type is so defined.
If the returned Promise rejects, it MUST reject with a
ProviderRpcError
as specified in the RPC Errors section below.The returned Promise MUST reject if any of the following conditions are met:
ProviderRpcError
interface, the Promise MAY reject with that error directly.The returned Promise SHOULD reject if any of the following conditions are met:
code
MUST be4900
.code
MUST be4901
.See the section Connectivity for the definitions of "connected" and "disconnected".
Supported RPC Methods
A "supported RPC method" is any RPC method that may be called via the Provider.
All supported RPC methods MUST be identified by unique strings.
Providers MAY support whatever RPC methods required to fulfill their purpose, standardized or otherwise.
If an RPC method defined in a finalized AIP is not supported, it SHOULD be rejected with a
4200
error per the Provider Errors section below, or an appropriate error per the RPC method's specification.RPC Errors
message
code
data
Error Standards
ProviderRpcError
codes and messages SHOULD follow these conventions, in order of priority:[CloseEvent
status codes](https://developer.mozilla.org/en-US/docs/Web/API/CloseEvent#Status_codes)Provider Errors
Events
The Provider MUST implement the following event handling methods:
on
removeListener
These methods MUST be implemented per the Node.js
[EventEmitter
API](https://nodejs.org/api/events.html).message
When emitted, the
message
event MUST be emitted with an object argument of the following form:connect
See the section Connectivity for the definition of "connected".
If the Provider becomes connected, the Provider MUST emit the event named
connect
.This includes when:
disconnect
event was emitted.This event MUST be emitted with an object of the following form:
chainId
MUST specify the integer ID of the connected chain as a hexadecimal string.disconnect
See the section Connectivity for the definition of "disconnected".
If the Provider becomes disconnected from all chains, the Provider MUST emit the event named
disconnect
with valueerror: ProviderRpcError
, per the interfaced defined in the RPC Errors section. The value of the error'scode
property MUST follow the status codes forCloseEvent
.chainChanged
If the chain the Provider is connected to changes, the Provider MUST emit the event named
chainChanged
with valuechainId: string
, specifying the integer ID of the new chain as a hexadecimal string.accountsChanged
If the accounts available to the Provider change, the Provider MUST emit the event named
accountsChanged
with valueaccounts: string[]
.Test Cases
Tests need to be implemented by Wallet apps so that the above specifications works as expected.
Reference Implementations (Dapps)
request
Makes an Aleo RPC method call.
The returned Promise resolves with the method's result or rejects with a
ProviderRpcError
. For example:Events
Events follow the conventions of the Node.js
[EventEmitter
API](https://nodejs.org/api/events.html).connect
The Provider emits
connect
when it:disconnect
event was emitted.disconnect
The Provider emits
disconnect
when it becomes disconnected.This event emits a
ProviderRpcError
. The errorcode
follows the table of[CloseEvent
status codes](https://developer.mozilla.org/en-US/docs/Web/API/CloseEvent#Status_codes).accountsChanged
The Provider emits
accountsChanged
if the accounts returned from the Provider change.The event emits with
accounts
, an array of account addresses.message
The Provider emits
message
to communicate arbitrary messages to the consumer. Messages may include JSON-RPC notifications, and/or any other event as defined by the Provider.Errors
Dependencies
Backwards Compatibility
Security & Compliance
This provider should not handle any private key or account management functionality since it will be exposed to an
untrusted environment.
References
We referenced [EIP-1193] heavily since it is a known and widely-used solution to this problem. Also, it will be
convenient for onboarding developers who are accustomed to Ethereum's interfaces.
Beta Was this translation helpful? Give feedback.
All reactions