Skip to content

Commit

Permalink
feat: eip-6963 support (#689)
Browse files Browse the repository at this point in the history
  • Loading branch information
gomesalexandre authored Oct 21, 2024
1 parent d20a7d9 commit c197ede
Show file tree
Hide file tree
Showing 94 changed files with 299 additions and 3,713 deletions.
2 changes: 0 additions & 2 deletions examples/sandbox/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,7 @@ <h4>Select</h4>
<button id="native">Pair Native</button>
<button id="metaMask">Pair MetaMask</button>
<button id="phantom">Pair Phantom</button>
<button id="xdefi">Pair XDEFI</button>
<button id="keplr">Pair Keplr</button>
<button id="tallyHo">Pair Tally Ho</button>
<button id="coinbase">Pair Coinbase</button>
<button id="walletConnect">Pair WalletConnect</button>
<button id="walletConnectV2">Pair WalletConnect V2</button>
Expand Down
42 changes: 2 additions & 40 deletions examples/sandbox/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,14 @@ import * as keepkeyWebUSB from "@shapeshiftoss/hdwallet-keepkey-webusb";
import * as keplr from "@shapeshiftoss/hdwallet-keplr";
import * as ledgerWebHID from "@shapeshiftoss/hdwallet-ledger-webhid";
import * as ledgerWebUSB from "@shapeshiftoss/hdwallet-ledger-webusb";
import * as metaMask from "@shapeshiftoss/hdwallet-metamask";
import * as metaMask from "@shapeshiftoss/hdwallet-metamask-multichain";
import * as native from "@shapeshiftoss/hdwallet-native";
import * as phantom from "@shapeshiftoss/hdwallet-phantom";
import * as portis from "@shapeshiftoss/hdwallet-portis";
import * as tallyHo from "@shapeshiftoss/hdwallet-tallyho";
import * as trezorConnect from "@shapeshiftoss/hdwallet-trezor-connect";
import { WalletConnectProviderConfig } from "@shapeshiftoss/hdwallet-walletconnect";
import * as walletConnect from "@shapeshiftoss/hdwallet-walletconnect";
import * as walletConnectv2 from "@shapeshiftoss/hdwallet-walletconnectv2";
import * as xdefi from "@shapeshiftoss/hdwallet-xdefi";
import { EthereumProviderOptions } from "@walletconnect/ethereum-provider/dist/types/EthereumProvider";
import { TypedData } from "eip-712";
import $, { noop } from "jquery";
Expand Down Expand Up @@ -126,12 +124,10 @@ const keepkeyAdapter = keepkeyWebUSB.WebUSBKeepKeyAdapter.useKeyring(keyring);
const kkbridgeAdapter = keepkeyTcp.TCPKeepKeyAdapter.useKeyring(keyring);
const kkemuAdapter = keepkeyTcp.TCPKeepKeyAdapter.useKeyring(keyring);
const portisAdapter = portis.PortisAdapter.useKeyring(keyring, { portisAppId });
const metaMaskAdapter = metaMask.MetaMaskAdapter.useKeyring(keyring);
const metaMaskAdapter = metaMask.MetaMaskAdapter.useKeyring(keyring, "io.metamask");
const phantomAdapter = phantom.PhantomAdapter.useKeyring(keyring);
const tallyHoAdapter = tallyHo.TallyHoAdapter.useKeyring(keyring);
const walletConnectAdapter = walletConnect.WalletConnectAdapter.useKeyring(keyring, walletConnectOptions);
const walletConnectV2Adapter = walletConnectv2.WalletConnectV2Adapter.useKeyring(keyring, walletConnectV2Options);
const xdefiAdapter = xdefi.XDEFIAdapter.useKeyring(keyring);
const keplrAdapter = keplr.KeplrAdapter.useKeyring(keyring);
const nativeAdapter = native.NativeAdapter.useKeyring(keyring);
const trezorAdapter = trezorConnect.TrezorAdapter.useKeyring(keyring, {
Expand Down Expand Up @@ -162,10 +158,8 @@ const $native = $("#native");
const $metaMask = $("#metaMask");
const $phantom = $("#phantom");
const $coinbase = $("#coinbase");
const $tallyHo = $("#tallyHo");
const $walletConnect = $("#walletConnect");
const $walletConnectV2 = $("#walletConnectV2");
const $xdefi = $("#xdefi");
const $keplr = $("#keplr");
const $keyring = $("#keyring");

Expand Down Expand Up @@ -284,19 +278,6 @@ $keplr.on("click", async (e) => {
}
});

$tallyHo.on("click", async (e) => {
e.preventDefault();
wallet = await tallyHoAdapter.pairDevice();
window["wallet"] = wallet;
let deviceID = "nothing";
try {
deviceID = await wallet.getDeviceID();
$("#keyring select").val(deviceID);
} catch (error) {
console.error(error);
}
});

$walletConnect.on("click", async (e) => {
e.preventDefault();
try {
Expand All @@ -323,19 +304,6 @@ $walletConnectV2.on("click", async (e) => {
}
});

$xdefi.on("click", async (e) => {
e.preventDefault();
wallet = await xdefiAdapter.pairDevice();
window["wallet"] = wallet;
let deviceID = "nothing";
try {
deviceID = await wallet.getDeviceID();
$("#keyring select").val(deviceID);
} catch (error) {
console.error(error);
}
});

async function deviceConnected(deviceId) {
wallet = keyring.get(deviceId);
if (!$keyring.find(`option[value="${deviceId}"]`).length) {
Expand Down Expand Up @@ -426,12 +394,6 @@ async function deviceConnected(deviceId) {
console.error("Could not initialize PhantomAdapter", e);
}

try {
await tallyHoAdapter.initialize();
} catch (e) {
console.error("Could not initialize TallyHoAdapter", e);
}

try {
await keplrAdapter.initialize();
} catch (e) {
Expand Down
38 changes: 18 additions & 20 deletions examples/sandbox/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@shapeshiftoss/hdwallet-sandbox",
"version": "1.55.10",
"version": "1.55.11",
"license": "MIT",
"private": true,
"browserslist": "> 0.5%, last 2 versions, not dead",
Expand All @@ -12,25 +12,23 @@
"dependencies": {
"@esm2cjs/p-queue": "^7.3.0",
"@metamask/eth-sig-util": "^7.0.0",
"@shapeshiftoss/hdwallet-coinbase": "1.55.10",
"@shapeshiftoss/hdwallet-core": "1.55.10",
"@shapeshiftoss/hdwallet-keepkey": "1.55.10",
"@shapeshiftoss/hdwallet-keepkey-tcp": "1.55.10",
"@shapeshiftoss/hdwallet-keepkey-webusb": "1.55.10",
"@shapeshiftoss/hdwallet-keplr": "1.55.10",
"@shapeshiftoss/hdwallet-ledger": "1.55.10",
"@shapeshiftoss/hdwallet-ledger-webhid": "1.55.10",
"@shapeshiftoss/hdwallet-ledger-webusb": "1.55.10",
"@shapeshiftoss/hdwallet-metamask": "1.55.10",
"@shapeshiftoss/hdwallet-native": "1.55.10",
"@shapeshiftoss/hdwallet-phantom": "1.55.10",
"@shapeshiftoss/hdwallet-portis": "1.55.10",
"@shapeshiftoss/hdwallet-tallyho": "1.55.10",
"@shapeshiftoss/hdwallet-trezor": "1.55.10",
"@shapeshiftoss/hdwallet-trezor-connect": "1.55.10",
"@shapeshiftoss/hdwallet-walletconnect": "1.55.10",
"@shapeshiftoss/hdwallet-walletconnectv2": "1.55.10",
"@shapeshiftoss/hdwallet-xdefi": "1.55.10",
"@shapeshiftoss/hdwallet-coinbase": "1.55.11",
"@shapeshiftoss/hdwallet-core": "1.55.11",
"@shapeshiftoss/hdwallet-keepkey": "1.55.11",
"@shapeshiftoss/hdwallet-keepkey-tcp": "1.55.11",
"@shapeshiftoss/hdwallet-keepkey-webusb": "1.55.11",
"@shapeshiftoss/hdwallet-keplr": "1.55.11",
"@shapeshiftoss/hdwallet-ledger": "1.55.11",
"@shapeshiftoss/hdwallet-ledger-webhid": "1.55.11",
"@shapeshiftoss/hdwallet-ledger-webusb": "1.55.11",
"@shapeshiftoss/hdwallet-metamask-multichain": "1.55.11",
"@shapeshiftoss/hdwallet-native": "1.55.11",
"@shapeshiftoss/hdwallet-phantom": "1.55.11",
"@shapeshiftoss/hdwallet-portis": "1.55.11",
"@shapeshiftoss/hdwallet-trezor": "1.55.11",
"@shapeshiftoss/hdwallet-trezor-connect": "1.55.11",
"@shapeshiftoss/hdwallet-walletconnect": "1.55.11",
"@shapeshiftoss/hdwallet-walletconnectv2": "1.55.11",
"bip32": "^2.0.4",
"eip-712": "^1.0.0",
"jquery": "^3.7.1",
Expand Down
20 changes: 10 additions & 10 deletions integration/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@shapeshiftoss/integration",
"version": "1.55.10",
"version": "1.55.11",
"main": "index.js",
"license": "MIT",
"private": true,
Expand All @@ -10,15 +10,15 @@
"dev": "lerna run test --scope integration --parallel --include-filtered-dependencies"
},
"dependencies": {
"@shapeshiftoss/hdwallet-core": "1.55.10",
"@shapeshiftoss/hdwallet-keepkey": "1.55.10",
"@shapeshiftoss/hdwallet-keepkey-nodewebusb": "1.55.10",
"@shapeshiftoss/hdwallet-keepkey-tcp": "1.55.10",
"@shapeshiftoss/hdwallet-ledger": "1.55.10",
"@shapeshiftoss/hdwallet-native": "1.55.10",
"@shapeshiftoss/hdwallet-portis": "1.55.10",
"@shapeshiftoss/hdwallet-trezor": "1.55.10",
"@shapeshiftoss/hdwallet-xdefi": "1.55.10",
"@shapeshiftoss/hdwallet-core": "1.55.11",
"@shapeshiftoss/hdwallet-keepkey": "1.55.11",
"@shapeshiftoss/hdwallet-keepkey-nodewebusb": "1.55.11",
"@shapeshiftoss/hdwallet-keepkey-tcp": "1.55.11",
"@shapeshiftoss/hdwallet-ledger": "1.55.11",
"@shapeshiftoss/hdwallet-metamask-multichain": "1.55.11",
"@shapeshiftoss/hdwallet-native": "1.55.11",
"@shapeshiftoss/hdwallet-portis": "1.55.11",
"@shapeshiftoss/hdwallet-trezor": "1.55.11",
"fast-json-stable-stringify": "^2.1.0",
"msw": "^0.27.1",
"whatwg-fetch": "^3.6.2"
Expand Down
52 changes: 25 additions & 27 deletions integration/src/bitcoin/bitcoin.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as core from "@shapeshiftoss/hdwallet-core";
import * as ledger from "@shapeshiftoss/hdwallet-ledger";
import * as metamask from "@shapeshiftoss/hdwallet-metamask-multichain";
import * as native from "@shapeshiftoss/hdwallet-native";
import * as phantom from "@shapeshiftoss/hdwallet-phantom";
import * as portis from "@shapeshiftoss/hdwallet-portis";
Expand Down Expand Up @@ -62,6 +63,8 @@ export function bitcoinTests(get: () => { wallet: core.HDWallet; info: core.HDWa
"btcSupportsCoin()",
async () => {
if (!wallet || portis.isPortis(wallet)) return;
// Non-EVM things are a pain to test with snaps on test env, this wasn't tested before and still isn't
if (metamask.isMetaMask(wallet)) return;
expect(wallet.btcSupportsCoin("Bitcoin")).toBeTruthy();
expect(await info.btcSupportsCoin("Bitcoin")).toBeTruthy();
},
Expand All @@ -71,7 +74,7 @@ export function bitcoinTests(get: () => { wallet: core.HDWallet; info: core.HDWa
test(
"btcSupportsCoin() - Testnet",
async () => {
if (!wallet || portis.isPortis(wallet) || phantom.isPhantom(wallet)) return;
if (!wallet || portis.isPortis(wallet) || phantom.isPhantom(wallet) || metamask.isMetaMask(wallet)) return;
expect(wallet.btcSupportsCoin("Testnet")).toBeTruthy();
expect(await info.btcSupportsCoin("Testnet")).toBeTruthy();
},
Expand All @@ -88,6 +91,9 @@ export function bitcoinTests(get: () => { wallet: core.HDWallet; info: core.HDWa
)
return;

// Non-EVM things are a pain to test with snaps on test env, this wasn't tested before and still isn't
if (metamask.isMetaMask(wallet)) return;

/* FIXME: Expected failure (trezor does not use scriptType in deriving public keys
and ledger's dependency bitcoinjs-lib/src/crypto.js throws a mysterious TypeError
in between mock transport calls.
Expand Down Expand Up @@ -210,10 +216,14 @@ export function bitcoinTests(get: () => { wallet: core.HDWallet; info: core.HDWa
const scriptType = args[3] as core.BTCInputScriptType;
const expected = args[4] as string;

// Non-EVM things are a pain to test with snaps on test env, this wasn't tested before and still isn't
if (metamask.isMetaMask(wallet)) return;

if (!(await wallet.btcSupportsCoin(coin))) return;
expect(await info.btcSupportsCoin(coin)).toBeTruthy();
if (!(await wallet.btcSupportsScriptType(coin, scriptType))) return;
expect(await info.btcSupportsScriptType(coin, scriptType)).toBeTruthy();

const res = await wallet.btcGetAddress({
addressNList: core.bip32ToAddressNList(path),
coin: coin,
Expand All @@ -230,7 +240,7 @@ export function bitcoinTests(get: () => { wallet: core.HDWallet; info: core.HDWa
test(
"btcSignTx() - p2pkh",
async () => {
if (!wallet || portis.isPortis(wallet) || phantom.isPhantom(wallet)) return;
if (!wallet || portis.isPortis(wallet) || phantom.isPhantom(wallet) || metamask.isMetaMask(wallet)) return;
if (ledger.isLedger(wallet)) return; // FIXME: Expected failure
const tx: core.BitcoinTx = {
version: 1,
Expand Down Expand Up @@ -305,7 +315,7 @@ export function bitcoinTests(get: () => { wallet: core.HDWallet; info: core.HDWa
test(
"btcSignTx() - thorchain swap",
async () => {
if (!wallet || portis.isPortis(wallet) || phantom.isPhantom(wallet)) return;
if (!wallet || portis.isPortis(wallet) || phantom.isPhantom(wallet) || metamask.isMetaMask(wallet)) return;
if (ledger.isLedger(wallet)) return; // FIXME: Expected failure
if (trezor.isTrezor(wallet)) return; //TODO: Add trezor support for op return data passed at top level
const tx: core.BitcoinTx = {
Expand Down Expand Up @@ -391,6 +401,8 @@ export function bitcoinTests(get: () => { wallet: core.HDWallet; info: core.HDWa
"btcSignMessage()",
async () => {
if (!wallet) return;
// Non-EVM things are a pain to test with snaps on test env, this wasn't tested before and still isn't
if (metamask.isMetaMask(wallet)) return;

// not implemented for native
if (native.isNative(wallet)) {
Expand Down Expand Up @@ -424,6 +436,8 @@ export function bitcoinTests(get: () => { wallet: core.HDWallet; info: core.HDWa
"btcVerifyMessage() - good",
async () => {
if (!wallet) return;
// Non-EVM things are a pain to test with snaps on test env, this wasn't tested before and still isn't
if (metamask.isMetaMask(wallet)) return;

// not implemented for native
if (native.isNative(wallet)) {
Expand All @@ -447,6 +461,8 @@ export function bitcoinTests(get: () => { wallet: core.HDWallet; info: core.HDWa
"btcVerifyMessage() - bad",
async () => {
if (!wallet) return;
// Non-EVM things are a pain to test with snaps on test env, this wasn't tested before and still isn't
if (metamask.isMetaMask(wallet)) return;

// not implemented for native
if (native.isNative(wallet)) {
Expand All @@ -470,6 +486,8 @@ export function bitcoinTests(get: () => { wallet: core.HDWallet; info: core.HDWa
"btcSupportsSecureTransfer()",
async () => {
if (!wallet) return;
// Non-EVM things are a pain to test with snaps on test env, this wasn't tested before and still isn't
if (metamask.isMetaMask(wallet)) return;
expect(typeof (await wallet.btcSupportsSecureTransfer()) === typeof true).toBeTruthy();
if (await wallet.btcSupportsSecureTransfer()) {
// eslint-disable-next-line jest/no-conditional-expect
Expand All @@ -484,6 +502,8 @@ export function bitcoinTests(get: () => { wallet: core.HDWallet; info: core.HDWa
"btcSupportsNativeShapeShift()",
async () => {
if (!wallet) return;
// Non-EVM things are a pain to test with snaps on test env, this wasn't tested before and still isn't
if (metamask.isMetaMask(wallet)) return;
expect(typeof wallet.btcSupportsNativeShapeShift()).toBe("boolean");
if (wallet.btcSupportsNativeShapeShift()) {
// eslint-disable-next-line jest/no-conditional-expect
Expand Down Expand Up @@ -515,6 +535,8 @@ export function bitcoinTests(get: () => { wallet: core.HDWallet; info: core.HDWa
const accountIdx = args[1] as number;
const scriptType = args[2] as core.BTCInputScriptType;
if (!wallet) return;
// Non-EVM things are a pain to test with snaps on test env, this wasn't tested before and still isn't
if (metamask.isMetaMask(wallet)) return;
if (!(await wallet.btcSupportsCoin(coin))) return;
expect(await info.btcSupportsCoin(coin)).toBeTruthy();
if (!(await wallet.btcSupportsScriptType(coin, scriptType))) return;
Expand All @@ -537,29 +559,5 @@ export function bitcoinTests(get: () => { wallet: core.HDWallet; info: core.HDWa
},
TIMEOUT
);

test(
"btcIsSameAccount()",
async () => {
if (!wallet || phantom.isPhantom(wallet)) return;
[0, 1, 9].forEach((idx) => {
const paths = wallet.btcGetAccountPaths({
coin: "Bitcoin",
accountIdx: idx,
});
expect(typeof wallet.btcIsSameAccount(paths) === typeof true).toBeTruthy();
paths.forEach((path) => {
if (wallet.getVendor() === "Portis") {
// eslint-disable-next-line jest/no-conditional-expect
expect(wallet.btcNextAccountPath(path)).toBeUndefined();
} else {
// eslint-disable-next-line jest/no-conditional-expect
expect(wallet.btcNextAccountPath(path)).not.toBeUndefined();
}
});
});
},
TIMEOUT
);
});
}
19 changes: 3 additions & 16 deletions integration/src/bitcoin/litecoin.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as core from "@shapeshiftoss/hdwallet-core";
import * as metamask from "@shapeshiftoss/hdwallet-metamask-multichain";

import { each } from "../utils";

Expand Down Expand Up @@ -32,6 +33,8 @@ export function litecoinTests(get: () => { wallet: core.HDWallet; info: core.HDW
"btcGetAddress()",
async () => {
if (!wallet) return;
// Non-EVM things are a pain to test with snaps on test env, this wasn't tested before and still isn't
if (metamask.isMetaMask(wallet)) return;
if (!(await wallet.btcSupportsCoin("Litecoin"))) return;
await each(
[
Expand Down Expand Up @@ -105,21 +108,5 @@ export function litecoinTests(get: () => { wallet: core.HDWallet; info: core.HDW
},
TIMEOUT
);

test(
"btcIsSameAccount()",
async () => {
if (!wallet) return;
if (!(await wallet.btcSupportsCoin("Litecoin"))) return;
[0, 1, 9].forEach((idx) => {
const paths = wallet.btcGetAccountPaths({
coin: "Litecoin",
accountIdx: idx,
});
expect(typeof wallet.btcIsSameAccount(paths) === typeof true).toBeTruthy();
});
},
TIMEOUT
);
});
}
Loading

0 comments on commit c197ede

Please sign in to comment.