Process signMessage request in Solana provider

This commit is contained in:
Ivan Grachev 2022-02-23 17:07:13 +03:00
parent f37d4321a9
commit 22c4653df1
4 changed files with 19 additions and 5 deletions

View File

@ -7,7 +7,7 @@ extension SafariRequest {
struct Solana: SafariRequestBody {
enum Method: String, Decodable, CaseIterable {
case connect
case connect, signMessage
}
let method: Method
@ -21,6 +21,8 @@ extension SafariRequest {
switch method {
case .connect:
return true
case .signMessage:
return false
}
}

File diff suppressed because one or more lines are too long

View File

@ -62,9 +62,11 @@ class TokenarySolana extends EventEmitter {
}
signMessage(encodedMessage, display) {
// display == "utf8"
// i've seen undefined display as well
// const signedMessage = await window.solana.signMessage(encodedMessage, "utf8");
var params = {message: encodedMessage};
if (typeof display !== "undefined") {
params.display = display;
}
return this.request({method: "signMessage", params: params});
}
request(payload) {
@ -86,6 +88,7 @@ class TokenarySolana extends EventEmitter {
});
switch (payload.method) {
case "connect":
case "signMessage":
return this.processPayload(payload);
default:
this.callbacks.delete(payload.id);
@ -132,6 +135,8 @@ class TokenarySolana extends EventEmitter {
this.emitConnect();
return this.sendResponse(payload.id, {publicKey: this.publicKey});
}
case "signMessage":
return this.postMessage("signMessage", payload.id, payload);
}
}
@ -162,6 +167,10 @@ class TokenarySolana extends EventEmitter {
this.sendResponse(id, {publicKey: publicKey});
this.emitConnect();
}
if ("result" in response) {
this.sendResponse(id, response.result);
}
}
postMessage(handler, id, data) {

View File

@ -39,6 +39,9 @@ struct DappRequestProcessor {
case .connect:
let responseBody = ResponseToExtension.Solana(publicKey: "26qv4GCcx98RihuK3c4T6ozB3J7L6VwCuFVc7Ta2A3Uo")
respond(to: request, body: .solana(responseBody), completion: completion)
case .signMessage:
// TODO: sign message
return .justShowApp
}
case .tezos:
respond(to: request, error: "Tezos is not supported yet", completion: completion)