-
Notifications
You must be signed in to change notification settings - Fork 113
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Dapi for N3 #145
base: master
Are you sure you want to change the base?
Dapi for N3 #145
Conversation
I'm a proponent of standardizing the protocol as long as it does not impact the transport layer of any solution. Ultimately, most of this interfacing will be handled by sdks which abstract a lot of this so its primarily a standard for tooling developers. I would also like to request that we generalize the name of this standard since |
nep-20.mediawiki
Outdated
|
||
In order for dapps to have a unified method of obtaining <code>IDapiProvider</code> instances, all providers must trigger the <code>Neo.DapiProvider.ready</code> event of the <code>window</code> object when they are ready. | ||
|
||
The front end of the dapp can listen to the event and obtain the <code>IDapiProvider</code> instance from the <code>detail</code> property of the event. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is fine for web based dapp clients, but what about mobile or desktop clients?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it is difficult for mobile clients and desktop clients to have a unified method to obtain IDapiProvider
objects.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It doesn't have to be a unified method, but I'd expect there to be some method for mobile and desktop apps to access a DAPI provider
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you have any ideas?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
WalletConnect 2.0 handles this using a "connection code": It could open the wallet via Deeplinking or show the code as an QRCode image, and then, on the Wallet the user can confirm the connection. So, for this to work, we would need a new event, so the dapp can handle this UI interaction to show the code.
nep-20.mediawiki
Outdated
|
||
==Rationale== | ||
|
||
This protocol will allow dApp developers to create applications that interact with the NEO blockchain without having to be concerned about managing a full wallet within their application or the details related to handing transaction creation or broadcasting. This will also allow dApps to allow users to transact in a secure fashion that does not require sharing of their private key. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this intended to be a protocol or an API? the specification above appears to be a Typescript API, but here it's described as a protocol (which would imply the possibility of multiple implementations in different programming languages)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Currently, the front end of most dapps is Javascript running in browsers.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Currently, the front end of most dapps is Javascript running in browsers.
This doesn't answer my "is this intended to be a protocol or api" question
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The specification describes the interfaces, so it is a protocol. Different wallet providers can have different implementations, but the interaction protocol with dapps is the same.
Hello, I just have a few minor considerations regarding this specification: I've tested Dapi with NeoLine in the past and also by checking it's documentation, I understood that the Chrome Extension doesn't need a proper "connection"
I believe it could be an interesting addition.
|
Many websites require users to log in to provide services. The
I think it should be provided in SDK.
It has been renamed to
I think it should be provided in SDK. |
What is the relationship of this to WalletConnect? Are they complementary or competitive? |
Dapi is a protocol for communication between plug-in wallet and dapp via javascript. And WalletConnect allows communication between the two through a centralized server to relay messages. |
nep-20.mediawiki
Outdated
// Represents the name of the event in IDapiProvider. | ||
export type EventName = | ||
"accountschanged" | // Triggered when the accounts in the wallet change. | ||
"networkchanged"; // Triggered when the user switches the current network. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we have a new event for connectionProposal
that could be emitted to deliver a connection code? The dapp could show it as QRCode to stablish a connection. This is very important for mobile Wallets.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't quite understand the role of connectionProposal
. Can you draw a flowchart to explain it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Hey, I just made this, I hope it could be helpful:
- Also, I wrote about it on this Readme
- And also, I wrote this while I was investingating it:
Wallet Connect implementation
Wallet Connect is a protocol to allow a safer communication between dApp and Wallet. It works with any blockchain because it simply creates a WebSocket server that handles the communication between dApp and Wallet in a smart way, handling format validation, problems with internet connection, cache, log, etc. It's client-side libraries helps to integrate even further, allowing the user to scan a QR Code to connect the two ends.
The parts
Server
A simple middleman that handles the communication between the other parts. At first, we believe we would need to change Wallet Connect relay server so it could work with Neo Blockchain and then send a pull request. But after exploring its code, it looks like we can simply use Wallet Connect server as it is right now.
dApp
A dApp is an application that uses smart contracts and other technologies as server-side. To securely reach the Smart Contracts, the user must use its own Wallet to sign the operations, and the responsible to delegate such interaction is the dApp's client-side. Firstly, the dApp establishes a connection with Wallet Connect which asks the user to scan the QR Code, by doing this, Wallet Connect knows how to make an end-to-end encryption and transfer information between the dApp and the Wallet. Now, the dApp can request to do an operation on the blockchain using the user's Wallet. By using JsonRPC format, it says which method and arguments it wants to call.
Wallet
The Wallet is a client-side application that allows the user to handle its assets, sign documents and interact with Smart Contracts. If integrated with Wallet Connect, it can receive messages from dApps that requests the user to procced with a blockchain operation. When receiving such methods, the Wallet should ask for user authorization and then call the blockchain method by itself. A good UX pattern is to show a mobile notification so the user can allow it without having to open the app by himself.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As I said:
Dapi is a protocol for communication between plug-in wallet and dapp via javascript. And WalletConnect allows communication between the two through a centralized server to relay messages.
They are different.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, but they focus solving the same problem. Are we going to exclude the possibility for WalletConnect integration on this specification? I mean, if the dapp wants to have multiple dapp-wallet integration providers, WalletConnect couldn't be one of them? Meaning that there will be absolutely no mobile wallet providers.
I think it should be possible for a dapp to provide a signature to a transaction created using the Dapi. From what I understand it should not increase risk for users, only for dApps that need to be careful they don't provide a signature to a malicious transaction. My imagined use case is for subsidizing transactions as the first signer, but I imagine there are others situations where apps might want to join in a multisig or approve certain contract calls. |
|
signMessage(message: Base64Encoded, account?: UInt160): Promise<{ signature: Base64Encoded; account: UInt160; pubkey: ECPoint }>; | ||
|
||
} | ||
</pre> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about ask wallet to add Network and Switch to another Network?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would like that the authors of the proposals checked that and solved the issues pending. Maybe it is needed or not.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've never used it, so just some nitpicking. Likely we need more input from providers/consumers of this API.
export type Address = string; | ||
|
||
// A 160-bit hash represented by a hexadecimal string. | ||
// Example: "0x682cca3ebdc66210e5847d7f8115846586079d4a" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What if it doesn't have a 0x
prefix, is it a valid UInt160?
export type UInt160 = string; | ||
|
||
// A 256-bit hash represented by a hexadecimal string. | ||
// Example: "0x1f4d1defa46faa5e7b9b8d3f79a06bec777d7c26c4aa5f6f5899a291daa87c15" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What if it doesn't have a 0x
prefix, is it a valid UInt256?
// Example: "03b209fd4f53a7170ea4444e0cb0a6bb6a53c2bd016926989cf85f9b0fba17a70c" | ||
export type ECPoint = string; | ||
|
||
// A large integer of any length expressed as a string. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is 1e8
a valid Integer?
export type HexString = string; | ||
|
||
// Represents a version. | ||
// Example: "1.0.0" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any specific requirements? SemVer?
"accountschanged" | // Triggered when the accounts in the wallet change. | ||
"networkchanged"; // Triggered when the user switches the current network. | ||
|
||
// Represents the type of ContractParameter. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NEP-14 should be referenced here.
type: ContractParameterType; // The type of the parameter. | ||
} | ||
|
||
// Represents an account in a wallet. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NEP-6 should be referenced here.
txid: UInt256; | ||
executions: { | ||
trigger: TriggerType; | ||
vmstate: VMState; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
abortOnFail?: boolean; // Indicates whether the entire transaction should fail when the contract returns `false`. | ||
} | ||
|
||
export type InvocationResult = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
notifications?
// Possible errors: UNSUPPORTED, INVALID, NOTFOUND, TIMEOUT, CANCELED. | ||
sign(context: ContractParametersContext): Promise<ContractParametersContext>; | ||
|
||
// Signs the message with the specified account. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is some specifics there usually like prefix added, it should be mentioned.
|
||
This protocol will allow dApp developers to create applications that interact with the NEO blockchain without having to be concerned about managing a full wallet within their application or the details related to handing transaction creation or broadcasting. This will also allow dApps to allow users to transact in a secure fashion that does not require sharing of their private key. | ||
|
||
==Implementation== |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From my last review I believe that this #145 (comment) was pending
No description provided.