-
Notifications
You must be signed in to change notification settings - Fork 174
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #354 from enkryptcom/feature/kadena-provider
feat: kadena provider
- Loading branch information
Showing
96 changed files
with
7,618 additions
and
235 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,12 @@ | ||
import EthereumProvider from "@/providers/ethereum"; | ||
import PolkadotProvider from "@/providers/polkadot"; | ||
import BitcoinProvider from "@/providers/bitcoin"; | ||
import KadenaProvider from "@/providers/kadena"; | ||
import { ProviderName } from "@/types/provider"; | ||
|
||
export default { | ||
[ProviderName.ethereum]: EthereumProvider, | ||
[ProviderName.polkadot]: PolkadotProvider, | ||
[ProviderName.bitcoin]: BitcoinProvider, | ||
[ProviderName.kadena]: KadenaProvider, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
import getRequestProvider, { RequestClass } from "@enkryptcom/request"; | ||
import { MiddlewareFunction, OnMessageResponse } from "@enkryptcom/types"; | ||
import Middlewares from "./methods"; | ||
import EventEmitter from "eventemitter3"; | ||
import { | ||
BackgroundProviderInterface, | ||
ProviderName, | ||
ProviderRPCRequest, | ||
} from "@/types/provider"; | ||
import GetUIPath from "@/libs/utils/get-ui-path"; | ||
import PublicKeyRing from "@/libs/keyring/public-keyring"; | ||
import UIRoutes from "./ui/routes/names"; | ||
|
||
import Networks from "./networks"; | ||
import { BaseNetwork } from "@/types/base-network"; | ||
import { KadenaNetwork } from "./types/kadena-network"; | ||
|
||
class KadenaProvider | ||
extends EventEmitter | ||
implements BackgroundProviderInterface | ||
{ | ||
network: KadenaNetwork; | ||
requestProvider: RequestClass; | ||
middlewares: MiddlewareFunction[] = []; | ||
namespace: string; | ||
KeyRing: PublicKeyRing; | ||
UIRoutes = UIRoutes; | ||
toWindow: (message: string) => void; | ||
|
||
constructor( | ||
toWindow: (message: string) => void, | ||
network: KadenaNetwork = Networks.kadena | ||
) { | ||
super(); | ||
this.network = network; | ||
this.toWindow = toWindow; | ||
this.setMiddleWares(); | ||
this.requestProvider = getRequestProvider("", this.middlewares); | ||
this.requestProvider.on("notification", (notif: any) => { | ||
this.sendNotification(JSON.stringify(notif)); | ||
}); | ||
this.namespace = ProviderName.kadena; | ||
this.KeyRing = new PublicKeyRing(); | ||
} | ||
|
||
private setMiddleWares(): void { | ||
this.middlewares = Middlewares.map((mw) => mw.bind(this)); | ||
} | ||
|
||
setRequestProvider(network: BaseNetwork): void { | ||
this.network = network as KadenaNetwork; | ||
this.requestProvider.changeNetwork(network.node); | ||
} | ||
|
||
request(request: ProviderRPCRequest): Promise<OnMessageResponse> { | ||
return this.requestProvider | ||
.request(request) | ||
.then((res: any) => { | ||
return { | ||
result: JSON.stringify(res), | ||
}; | ||
}) | ||
.catch((e: { message: any }) => { | ||
return { | ||
error: JSON.stringify(e.message), | ||
}; | ||
}); | ||
} | ||
|
||
async sendNotification(notif: string): Promise<void> { | ||
return this.toWindow(notif); | ||
} | ||
|
||
async isPersistentEvent(): Promise<boolean> { | ||
return false; | ||
} | ||
|
||
getUIPath(page: string): string { | ||
return GetUIPath(page, this.namespace); | ||
} | ||
} | ||
|
||
export default KadenaProvider; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import EventEmitter from "eventemitter3"; | ||
import { handleIncomingMessage } from "./libs/message-handler"; | ||
import { EthereumRequest, EthereumResponse } from "@/providers/ethereum/types"; | ||
import { | ||
ProviderName, | ||
ProviderOptions, | ||
ProviderType, | ||
ProviderInterface, | ||
SendMessageHandler, | ||
} from "@/types/provider"; | ||
import { EnkryptWindow } from "@/types/globals"; | ||
import { KadenaNetworks } from "./types"; | ||
|
||
export class Provider extends EventEmitter implements ProviderInterface { | ||
connected: boolean; | ||
name: ProviderName; | ||
type: ProviderType; | ||
version = __VERSION__; | ||
autoRefreshOnNetworkChange = false; | ||
networks: typeof KadenaNetworks; | ||
sendMessageHandler: SendMessageHandler; | ||
|
||
constructor(options: ProviderOptions) { | ||
super(); | ||
this.connected = true; | ||
this.name = options.name; | ||
this.type = options.type; | ||
this.networks = KadenaNetworks; | ||
this.sendMessageHandler = options.sendMessageHandler; | ||
} | ||
|
||
async request(request: EthereumRequest): Promise<EthereumResponse> { | ||
const res = (await this.sendMessageHandler( | ||
this.name, | ||
JSON.stringify(request) | ||
)) as EthereumResponse; | ||
return res; | ||
} | ||
|
||
isConnected(): boolean { | ||
return this.connected; | ||
} | ||
|
||
handleMessage(msg: string): void { | ||
handleIncomingMessage(this, msg); | ||
} | ||
} | ||
|
||
const injectDocument = ( | ||
document: EnkryptWindow | Window, | ||
options: ProviderOptions | ||
): void => { | ||
const provider = new Provider(options); | ||
document["enkrypt"]["providers"][options.name] = provider; | ||
}; | ||
|
||
export default injectDocument; |
Oops, something went wrong.
a240c91
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.
Virus total analysis
chrome:
https://www.virustotal.com/gui/file/567eb25e6207bc17bed2031cf4704b5bd8229ba347b76830b265fdcc87d66042
firefox:
https://www.virustotal.com/gui/file/81c05b677c3566e78b1161ee89ee1a39f80545b5f90e19fcf05567e7be0a4d68