Skip to content

Commit

Permalink
Merge pull request #41 from airgap-it/feat/edonet
Browse files Browse the repository at this point in the history
feat(edonet): add edonet
  • Loading branch information
pascuin authored Feb 22, 2021
2 parents e78fc6a + 9db2199 commit e20bac3
Show file tree
Hide file tree
Showing 12 changed files with 84 additions and 76 deletions.
21 changes: 14 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "spire",
"version": "2.1.0",
"version": "2.2.0",
"author": "AirGap",
"homepage": "https://airgap.it/",
"scripts": {
Expand All @@ -25,7 +25,7 @@
},
"private": true,
"dependencies": {
"@airgap/beacon-sdk": "2.0.0",
"@airgap/beacon-sdk": "2.2.1",
"@airgap/coinlib-core": "0.10.0-beta.3",
"@angular/common": "^11.0.3",
"@angular/core": "^11.0.3",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { ModalController, ToastController } from '@ionic/angular'
export class AddWalletConnectionPage {
public handshakeData: string | undefined

constructor(private readonly modalController: ModalController, private readonly toastController: ToastController) { }
constructor(private readonly modalController: ModalController, private readonly toastController: ToastController) {}

public async dismiss(): Promise<void> {
await this.modalController.dismiss()
Expand Down
3 changes: 2 additions & 1 deletion src/app/pages/settings/settings.page.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
<ion-label>Active Network</ion-label>
<ion-select [(ngModel)]="networkType" (ionChange)="updateNetworkType()" placeholder="Select Network">
<ion-select-option value="mainnet">Mainnet</ion-select-option>
<ion-select-option value="carthagenet">Carthagenet</ion-select-option>
<ion-select-option value="delphinet">Delphinet</ion-select-option>
<ion-select-option value="edonet">Edonet</ion-select-option>
<ion-select-option value="custom">Custom</ion-select-option>
</ion-select>
</ion-item>
Expand Down
16 changes: 8 additions & 8 deletions src/app/services/settings.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,40 +40,40 @@ export class SettingsService {
public async getProtocolForNetwork(network: Network): Promise<TezosProtocol> {
const rpcUrls: { [key in NetworkType]: string } = {
[NetworkType.MAINNET]: 'https://tezos-node.prod.gke.papers.tech',
[NetworkType.CARTHAGENET]: 'https://tezos-carthagenet-node.prod.gke.papers.tech',
[NetworkType.DELPHINET]: 'https://tezos-delphinet-node.prod.gke.papers.tech',
[NetworkType.EDONET]: 'https://tezos-edonet-node.prod.gke.papers.tech',
[NetworkType.CUSTOM]: ''
}
const apiUrls: { [key in NetworkType]: string } = {
[NetworkType.MAINNET]: 'https://tezos-mainnet-conseil.prod.gke.papers.tech',
[NetworkType.CARTHAGENET]: 'https://tezos-carthagenet-conseil.prod.gke.papers.tech',
[NetworkType.DELPHINET]: 'https://tezos-delphinet-conseil.prod.gke.papers.tech',
[NetworkType.EDONET]: 'https://tezos-edonet-conseil.prod.gke.papers.tech',
[NetworkType.CUSTOM]: ''
}

const names: { [key in NetworkType]: string } = {
[NetworkType.MAINNET]: 'Mainnet',
[NetworkType.CARTHAGENET]: 'Carthagenet',
[NetworkType.DELPHINET]: 'Delphinet',
[NetworkType.EDONET]: 'Edonet',
[NetworkType.CUSTOM]: 'Custom'
}
const airgapNetworks: { [key in NetworkType]: AirGapNetworkType } = {
[NetworkType.MAINNET]: AirGapNetworkType.MAINNET,
[NetworkType.CARTHAGENET]: AirGapNetworkType.TESTNET,
[NetworkType.DELPHINET]: AirGapNetworkType.TESTNET,
[NetworkType.EDONET]: AirGapNetworkType.TESTNET,
[NetworkType.CUSTOM]: AirGapNetworkType.CUSTOM
}
const blockExplorers: { [key in NetworkType]: string } = {
[NetworkType.MAINNET]: 'https://tezblock.io',
[NetworkType.CARTHAGENET]: 'https://carthagenet.tezblock.io',
[NetworkType.DELPHINET]: 'https://delphinet.tezblock.io',
[NetworkType.CUSTOM]: 'https://delphinet.tezblock.io'
[NetworkType.EDONET]: 'https://edonet.tezblock.io',
[NetworkType.CUSTOM]: 'https://edonet.tezblock.io'
}
const tezosNetworks: { [key in NetworkType]: TezosNetwork } = {
[NetworkType.MAINNET]: TezosNetwork.MAINNET,
[NetworkType.CARTHAGENET]: TezosNetwork.DELPHINET,
[NetworkType.DELPHINET]: TezosNetwork.DELPHINET,
[NetworkType.CUSTOM]: TezosNetwork.DELPHINET
[NetworkType.EDONET]: TezosNetwork.EDONET,
[NetworkType.CUSTOM]: TezosNetwork.EDONET
}

const name: string = names[network.type]
Expand Down
78 changes: 36 additions & 42 deletions src/extension/extension-client/ExtensionClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,42 +144,42 @@ export class ExtensionClient extends BeaconClient {
data: ExtensionMessage<ExtensionMessageInputPayload<Action>>,
connectionContext: ConnectionContext
): Promise<void> => {
logger.log('handleMessage', data, connectionContext)
const handler: ActionHandlerFunction<Action> = await new ActionMessageHandler().getHandler(data.payload.action)

const p2pConnectedCallback = async (newPeer: ExtendedP2PPairingResponse): Promise<void> => {
console.log('CONNECTED')
if (newPeer) {
const walletInfo: WalletInfo<WalletType.P2P> = {
address: '',
publicKey: '',
type: WalletType.P2P,
added: new Date().getTime(),
info: newPeer
}
await this.addWallet(walletInfo)
await this.storage.set('ACTIVE_WALLET' as any, walletInfo)
logger.log('handleMessage', data, connectionContext)
const handler: ActionHandlerFunction<Action> = await new ActionMessageHandler().getHandler(data.payload.action)

const p2pConnectedCallback = async (newPeer: ExtendedP2PPairingResponse): Promise<void> => {
console.log('CONNECTED')
if (newPeer) {
const walletInfo: WalletInfo<WalletType.P2P> = {
address: '',
publicKey: '',
type: WalletType.P2P,
added: new Date().getTime(),
info: newPeer
}

this.popupManager
.sendToActivePopup({
target: ExtensionMessageTarget.EXTENSION,
sender: 'background',
payload: { beaconEvent: BeaconEvent.P2P_CHANNEL_CONNECT_SUCCESS }
})
.catch(console.error)
await this.addWallet(walletInfo)
await this.storage.set('ACTIVE_WALLET' as any, walletInfo)
}

await handler({
data: data.payload,
sendResponse: connectionContext.extras ? connectionContext.extras.sendResponse : () => undefined,
client: this,
p2pTransport: this.p2pTransport,
p2pTransportConnectedCallback: p2pConnectedCallback,
storage: this.storage
})
this.popupManager
.sendToActivePopup({
target: ExtensionMessageTarget.EXTENSION,
sender: 'background',
payload: { beaconEvent: BeaconEvent.PAIR_SUCCESS }
})
.catch(console.error)
}

await handler({
data: data.payload,
sendResponse: connectionContext.extras ? connectionContext.extras.sendResponse : () => undefined,
client: this,
p2pTransport: this.p2pTransport,
p2pTransportConnectedCallback: p2pConnectedCallback,
storage: this.storage
})
}

public async addListener(listener: Function): Promise<any> {
this.listeners.push(listener)
}
Expand Down Expand Up @@ -307,9 +307,9 @@ export class ExtensionClient extends BeaconClient {
const request:
| { message: BeaconMessage; connectionContext: ConnectionContext }
| undefined = this.pendingRequests.find(
(requestElement: { message: BeaconMessage; connectionContext: ConnectionContext }) =>
requestElement.message.id === response.id
)
(requestElement: { message: BeaconMessage; connectionContext: ConnectionContext }) =>
requestElement.message.id === response.id
)
if (!request) {
throw new Error('Matching request not found')
}
Expand All @@ -321,21 +321,15 @@ export class ExtensionClient extends BeaconClient {
}

const errorData = (beaconMessage as any).errorData as unknown
if (
errorData &&
(
!Array.isArray(errorData) ||
!errorData.every((item) => Boolean(item.kind) && Boolean(item.id))
)
) {
if (errorData && (!Array.isArray(errorData) || !errorData.every(item => Boolean(item.kind) && Boolean(item.id)))) {
logger.warn(
'ErrorData provided is not in correct format. It needs to be an array of RPC errors. It will not be included in the message sent to the dApp'
)
delete (beaconMessage as any).errorData
}

// TODO: Remove v1 compatibility in later version
; (beaconMessage as any).beaconId = beaconMessage.senderId
;(beaconMessage as any).beaconId = beaconMessage.senderId

const serialized = await new Serializer().serialize(beaconMessage)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,14 @@ export const operationRequestHandler: (client: ExtensionClient, logger: Logger)

const sendError: (error: Error, errorType: BeaconErrorType) => Promise<void> = async (
error: Error,
errorType: BeaconErrorType,
errorType: BeaconErrorType
): Promise<void> => {
logger.log('operationRequestHandler', 'error ', error)
responseInput = {
id: operationRequest.id,
type: BeaconMessageType.OperationResponse,
errorType,
errorData: (error as any as AxiosResponse).data
errorData: ((error as any) as AxiosResponse).data
} as any

const response: OperationResponse = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ export const permissionRequestHandler: (client: ExtensionClient, logger: Logger)

const response: PermissionResponse = {
senderId: await getSenderId(await client.beaconId),
appMetadata: {
senderId: await getSenderId(await client.beaconId),
name: await client.name
},
version: BEACON_VERSION,
...responseInput
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export class ChromeMessageTransport<
public readonly type: TransportType = TransportType.CHROME_MESSAGE

constructor(name: string, keyPair: sodium.KeyPair, storage: Storage, storageKey: K) {
super(name, new ChromeMessageClient(name, keyPair, false), new PeerManager(storage, storageKey))
super(name, new ChromeMessageClient(name, keyPair), new PeerManager(storage, storageKey))
this.init().catch(error => console.error(error))
this.connect().catch(error => console.error(error))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,9 @@ export class ToExtensionMessageHandler extends MessageHandler {
): Promise<void> => {
logger.log('handle', 'error', error)

const errorData = (error as any as AxiosResponse).data.data || (error as any as AxiosResponse).data
const errorData = ((error as any) as AxiosResponse).data
? ((error as any) as AxiosResponse).data.data || ((error as any) as AxiosResponse).data
: ((error as any) as AxiosResponse).data

const responseInput = {
id: deserialized.id,
Expand Down Expand Up @@ -114,7 +116,7 @@ export class ToExtensionMessageHandler extends MessageHandler {

if (deserialized.type === BeaconMessageType.OperationRequest) {
// Intercept Operation request and enrich it with information
; (async (): Promise<void> => {
;(async (): Promise<void> => {
const operationRequest: OperationRequestOutput = enriched.res as OperationRequestOutput

const wallet: WalletInfo | undefined = await this.client.getWalletByAddress(operationRequest.sourceAddress)
Expand Down
18 changes: 9 additions & 9 deletions src/extension/extension-client/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ export const getRpcUrlForNetwork: (network: Network) => Promise<{ rpcUrl: string
): Promise<{ rpcUrl: string; apiUrl: string }> => {
const rpcUrls: { [key in NetworkType]: string } = {
[NetworkType.MAINNET]: 'https://tezos-node.prod.gke.papers.tech',
[NetworkType.CARTHAGENET]: 'https://tezos-carthagenet-node.prod.gke.papers.tech',
[NetworkType.DELPHINET]: 'https://tezos-delphinet-node.prod.gke.papers.tech',
[NetworkType.EDONET]: 'https://tezos-edonet-node.prod.gke.papers.tech',
[NetworkType.CUSTOM]: ''
}
const apiUrls: { [key in NetworkType]: string } = {
[NetworkType.MAINNET]: 'https://tezos-mainnet-conseil.prod.gke.papers.tech',
[NetworkType.CARTHAGENET]: 'https://tezos-carthagenet-conseil.prod.gke.papers.tech',
[NetworkType.DELPHINET]: 'https://tezos-delphinet-conseil.prod.gke.papers.tech',
[NetworkType.EDONET]: 'https://tezos-edonet-conseil.prod.gke.papers.tech',
[NetworkType.CUSTOM]: ''
}

Expand All @@ -38,27 +38,27 @@ export const getProtocolForNetwork: (network: Network) => Promise<TezosProtocol>

const names: { [key in NetworkType]: string } = {
[NetworkType.MAINNET]: 'Mainnet',
[NetworkType.CARTHAGENET]: 'Carthagenet',
[NetworkType.DELPHINET]: 'Delphinet',
[NetworkType.EDONET]: 'Edonet',
[NetworkType.CUSTOM]: 'Custom'
}
const airgapNetworks: { [key in NetworkType]: AirGapNetworkType } = {
[NetworkType.MAINNET]: AirGapNetworkType.MAINNET,
[NetworkType.CARTHAGENET]: AirGapNetworkType.TESTNET,
[NetworkType.DELPHINET]: AirGapNetworkType.TESTNET,
[NetworkType.EDONET]: AirGapNetworkType.TESTNET,
[NetworkType.CUSTOM]: AirGapNetworkType.CUSTOM
}
const blockExplorers: { [key in NetworkType]: string } = {
[NetworkType.MAINNET]: 'https://tezblock.io',
[NetworkType.CARTHAGENET]: 'https://carthagenet.tezblock.io',
[NetworkType.DELPHINET]: 'https://delphinet.tezblock.io',
[NetworkType.CUSTOM]: 'https://delphinet.tezblock.io'
[NetworkType.EDONET]: 'https://edonet.tezblock.io',
[NetworkType.CUSTOM]: 'https://edonet.tezblock.io'
}
const tezosNetworks: { [key in NetworkType]: TezosNetwork } = {
[NetworkType.MAINNET]: TezosNetwork.MAINNET,
[NetworkType.CARTHAGENET]: TezosNetwork.DELPHINET,
[NetworkType.DELPHINET]: TezosNetwork.DELPHINET,
[NetworkType.CUSTOM]: TezosNetwork.DELPHINET
[NetworkType.EDONET]: TezosNetwork.EDONET,
[NetworkType.CUSTOM]: TezosNetwork.EDONET
}

const name: string = names[network.type]
Expand Down Expand Up @@ -86,8 +86,8 @@ export const getTezblockLinkForNetwork: (network: Network | undefined) => Promis

const urls: { [key in NetworkType]: string } = {
[NetworkType.MAINNET]: 'https://tezblock.io/account/',
[NetworkType.CARTHAGENET]: 'https://carthagenet.tezblock.io/account/',
[NetworkType.DELPHINET]: 'https://delphinet.tezblock.io/account/',
[NetworkType.EDONET]: 'https://edonet.tezblock.io/account/',
[NetworkType.CUSTOM]: 'http://localhost:8100/account/'
}
const url: string = urls[network ? network.type : NetworkType.MAINNET]
Expand Down
2 changes: 1 addition & 1 deletion src/manifest.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "Spire",
"version": "2.1.0",
"version": "2.2.0",
"description": "Spire allows you to interact with Tezos dApps that support the Beacon SDK.",
"icons": {
"16": "assets/icon/spire-logo-16px.png",
Expand Down

0 comments on commit e20bac3

Please sign in to comment.