Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions examples/react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"@cosmjs/crypto": "^0.38.1",
"@cosmjs/proto-signing": "^0.38.1",
"@esbuild-plugins/node-globals-polyfill": "^0.2.3",
"@interchain-kit/aria-extension": "workspace:*",
"@interchain-kit/backpack-extension": "workspace:*",
"@interchain-kit/coin98-extension": "workspace:*",
"@interchain-kit/compass-extension": "workspace:*",
Expand Down
2 changes: 2 additions & 0 deletions examples/react/src/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import { trustWallet } from '@interchain-kit/trust-extension';
import { leapCosmosExtensionMetaMask } from '@interchain-kit/leap-cosmos-extension-metamask';
import { xdefinWallet } from '@interchain-kit/xdefi-extension';
import { vultisigWallet } from '@interchain-kit/vultisig-extension';
import { ariaWallet } from '@interchain-kit/aria-extension';
// import { MockWallet } from "@interchain-kit/mock-wallet";
import { metaMaskWallet } from '@interchain-kit/metamask-extension';
import { exodusWallet } from '@interchain-kit/exodus-extension';
Expand Down Expand Up @@ -218,6 +219,7 @@ const _wallets: BaseWallet[] = [
// backPackWallet,
// solflareWallet,
// vultisigWallet,
// ariaWallet,
];

ReactDOM.createRoot(document.getElementById('root')!).render(
Expand Down
14 changes: 14 additions & 0 deletions pnpm-lock.yaml

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

43 changes: 43 additions & 0 deletions wallets/aria-extension/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# @interchain-kit/aria-extension

Aria browser extension wallet adapter for [Interchain Kit](https://github.com/hyperweb-io/interchain-kit).

[Aria](https://aria.orchestralabs.org) is a multi-chain wallet by Orchestra Labs. This package connects dApps to `window.aria`, Aria's Keplr-compatible provider, for Cosmos chains, to `window.aria.ethereum` for EVM chains, and to `window.aria.solana` for Solana.

## Install

```sh
npm install @interchain-kit/aria-extension @interchain-kit/react
```

## Usage

```tsx
import { ChainProvider } from '@interchain-kit/react';
import { ariaWallet } from '@interchain-kit/aria-extension';
import { chain as cosmoshubChain, assetList as cosmoshubAssetList } from 'chain-registry/mainnet/cosmoshub';

export function App() {
return (
<ChainProvider
chains={[cosmoshubChain]}
assetLists={[cosmoshubAssetList]}
wallets={[ariaWallet]}
>
{/* your app */}
</ChainProvider>
);
}
```

## Requirements

- [Aria extension](https://chromewebstore.google.com/detail/aria-wallet/cgghllcclkhfpkjhgomhehlebgphifbm) installed (Chrome)

## How it works

The adapter detects Aria via `window.aria` and uses the standard `CosmosWallet` implementation (`enable`, `getKey`, `signAmino`, `signDirect`, `signArbitrary`, `sendTx`, etc.) `EthereumWallet` for EVM chains, and `SolanaWallet` for Solana.

Aria's `enable` connects the site without checking the chain, so on connect the adapter asks Aria for the account key and, if Aria reports the chain as unknown, suggests it through `experimentalSuggestChain` with the chain's registry data.

On Solana, connect first tells Aria the chain's cluster (`changeCluster`): devnet or testnet when the chain's RPC names one, as Solana's wallet adapter reads an endpoint, else the cluster of its genesis-hash chain ID, else mainnet. Aria then simulates and sends that chain's transactions on that cluster, and refuses a cluster it has no RPCs for, such as a local validator.
130 changes: 130 additions & 0 deletions wallets/aria-extension/__tests__/first.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
import { CosmosWallet, EthereumWallet, SolanaWallet } from '@interchain-kit/core';

import { AriaCosmosWallet, ariaExtensionInfo, AriaSolanaWallet, ariaWallet, solanaCluster } from '../src';

describe('Aria extension', () => {
it('exposes correct wallet metadata', () => {
expect(ariaWallet.info.name).toBe('aria-extension');
expect(ariaWallet.info.prettyName).toBe('Aria');
expect(ariaWallet.info.mode).toBe('extension');
expect(ariaWallet.info.windowKey).toBe('aria');
expect(ariaWallet.info.cosmosKey).toBe('aria');
expect(ariaWallet.info.ethereumKey).toBe('aria.ethereum');
expect(ariaWallet.info.solanaKey).toBe('aria.solana');
expect(ariaWallet.info.keystoreChange).toBe('aria_keystorechange');
expect(ariaWallet.info.downloads).toEqual(
expect.arrayContaining([
expect.objectContaining({
browser: 'chrome',
link: 'https://chromewebstore.google.com/detail/aria-wallet/cgghllcclkhfpkjhgomhehlebgphifbm',
}),
]),
);
});

it('uses Aria for Cosmos, EVM and Solana chains', () => {
expect(ariaWallet.getWalletByChainType('cosmos')).toBeInstanceOf(AriaCosmosWallet);
expect(ariaWallet.getWalletByChainType('cosmos')).toBeInstanceOf(CosmosWallet);
expect(ariaWallet.getWalletByChainType('eip155')).toBeInstanceOf(EthereumWallet);
expect(ariaWallet.getWalletByChainType('solana')).toBeInstanceOf(AriaSolanaWallet);
expect(ariaWallet.getWalletByChainType('solana')).toBeInstanceOf(SolanaWallet);
});
});

describe('AriaCosmosWallet connect', () => {
const setup = (getKey: jest.Mock, enable = jest.fn().mockResolvedValue(undefined)) => {
const wallet = new AriaCosmosWallet(ariaExtensionInfo);
wallet.client = { enable, getKey };
const addSuggestChain = jest.spyOn(wallet, 'addSuggestChain').mockResolvedValue(undefined);
return { wallet, enable, addSuggestChain };
};

it('connects to a chain Aria knows without suggesting it', async () => {
const { wallet, enable, addSuggestChain } = setup(jest.fn().mockResolvedValue({}));

await wallet.connect('cosmoshub-4');

expect(enable).toHaveBeenCalledWith('cosmoshub-4');
expect(addSuggestChain).not.toHaveBeenCalled();
});

it('suggests a chain Aria does not know', async () => {
const { wallet, addSuggestChain } = setup(
jest
.fn()
.mockRejectedValue(new Error('Unknown chain: mychain-1. Add it via experimentalSuggestChain().')),
);

await wallet.connect('mychain-1');

expect(addSuggestChain).toHaveBeenCalledWith('mychain-1');
});

it('passes other getKey errors through', async () => {
const { wallet, addSuggestChain } = setup(jest.fn().mockRejectedValue(new Error('No accounts found in wallet')));

await expect(wallet.connect('cosmoshub-4')).rejects.toThrow('No accounts found in wallet');
expect(addSuggestChain).not.toHaveBeenCalled();
});

it('does not suggest a chain when the user rejects the connection', async () => {
const getKey = jest.fn();
const { wallet, addSuggestChain } = setup(
getKey,
jest.fn().mockRejectedValue(new Error('User rejected the connection request')),
);

await expect(wallet.connect('cosmoshub-4')).rejects.toThrow('User rejected the connection request');
expect(getKey).not.toHaveBeenCalled();
expect(addSuggestChain).not.toHaveBeenCalled();
});
});

describe('AriaSolanaWallet connect', () => {
const solanaChain = (chainId: string | undefined, rpc?: string): any => ({
chainName: `solana-${chainId}`,
chainType: 'solana',
chainId,
...(rpc ? { apis: { rpc: [{ address: rpc }] } } : {}),
});
const setup = (chains: any[], changeCluster = jest.fn().mockResolvedValue({})) => {
const wallet = new AriaSolanaWallet(ariaExtensionInfo);
wallet.setChainMap(chains);
const connect = jest.fn().mockResolvedValue({ publicKey: 'So1' });
wallet.solana = { changeCluster, connect };
return { wallet, changeCluster, connect };
};

// interchain-kit's example names its devnet chain by testnet's genesis hash, on the devnet RPC
it("sets the chain's cluster in Aria before connecting", async () => {
const chain = solanaChain('4uhcVJyU9pJkvQyS88uRDiswHXSCkY3z', 'https://api.devnet.solana.com');
const { wallet, changeCluster, connect } = setup([chain]);

await wallet.connect(chain.chainId);

expect(changeCluster).toHaveBeenCalledWith('devnet');
expect(changeCluster.mock.invocationCallOrder[0]).toBeLessThan(connect.mock.invocationCallOrder[0]);
});

it('a chain Aria has no RPCs for is refused, and the site is not connected', async () => {
const chain = solanaChain('local', 'http://localhost:8899');
const refusal = Object.assign(new Error('Aria has no Solana cluster solana:localnet.'), { code: -32602 });
const { wallet, connect } = setup([chain], jest.fn().mockRejectedValue(refusal));

await expect(wallet.connect(chain.chainId)).rejects.toThrow('Aria has no Solana cluster solana:localnet.');
expect(connect).not.toHaveBeenCalled();
});

it.each([
['the RPC names devnet', 'devnet', solanaChain('x', 'https://devnet.helius-rpc.com/?api-key=k')],
['the RPC names testnet', 'testnet', solanaChain('x', 'https://api.testnet.solana.com')],
['a local RPC', 'localnet', solanaChain('x', 'http://127.0.0.1:8899')],
['the devnet genesis hash', 'devnet', solanaChain('EtWTRABZaYq6iMfeYKouRu166VU2xqa1')],
['the testnet CAIP-2 ID', 'testnet', solanaChain('solana:4uhcVJyU9pJkvQyS88uRDiswHXSCkY3z')],
['the mainnet genesis hash', 'mainnet', solanaChain('5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp')],
["a mainnet provider's RPC", 'mainnet', solanaChain(undefined, 'https://mainnet.helius-rpc.com')],
['no chain at all', 'mainnet', undefined],
])('%s: %s', (_, cluster, chain) => {
expect(solanaCluster(chain, chain?.chainId)).toBe(cluster);
});
});
18 changes: 18 additions & 0 deletions wallets/aria-extension/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/** @type {import('ts-jest').JestConfigWithTsJest} */
module.exports = {
preset: 'ts-jest',
testEnvironment: 'node',
transform: {
'^.+\\.tsx?$': [
'ts-jest',
{
babelConfig: false,
tsconfig: 'tsconfig.json',
},
],
},
transformIgnorePatterns: [`/node_modules/*`],
testRegex: '(/__tests__/.*|(\\.|/)(test|spec))\\.(jsx?|tsx?)$',
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'],
modulePathIgnorePatterns: ['dist/*']
};
43 changes: 43 additions & 0 deletions wallets/aria-extension/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
{
"name": "@interchain-kit/aria-extension",
"version": "0.11.0",
"author": "Orchestra Labs <dblackstone@orchestralabs.org>",
"description": "Aria browser extension wallet adapter for Interchain Kit",
"main": "index.js",
"module": "esm/index.js",
"types": "index.d.ts",
"homepage": "https://github.com/hyperweb-io/interchain-kit",
"license": "MIT",
"publishConfig": {
"access": "public",
"directory": "dist"
},
"repository": {
"type": "git",
"url": "https://github.com/hyperweb-io/interchain-kit"
},
"bugs": {
"url": "https://github.com/hyperweb-io/interchain-kit/issues"
},
"scripts": {
"clean": "makage clean",
"build": "makage build",
"lint": "eslint . --fix",
"test": "jest",
"test:watch": "jest --watch",
"watch:dev": "tsc -w -p tsconfig.esm.json & tsc -w",
"prepack": "npm run build"
},
"keywords": [
"aria",
"cosmos",
"wallet",
"interchain-kit"
],
"dependencies": {
"@interchain-kit/core": "workspace:*"
},
"devDependencies": {
"makage": "^0.1.12"
}
}
Loading