Skip to content

Commit

Permalink
Merge pull request #624 from shapeshift/coinbase-wallet
Browse files Browse the repository at this point in the history
  • Loading branch information
0xdef1cafe authored Jun 13, 2023
2 parents 1164b0d + 5aa0b5f commit 3306a2d
Show file tree
Hide file tree
Showing 35 changed files with 1,178 additions and 90 deletions.
1 change: 1 addition & 0 deletions examples/sandbox/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ <h4>Select</h4>
<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>

<select id="keyring" style="height: 100px" size="4"></select>
Expand Down
31 changes: 31 additions & 0 deletions examples/sandbox/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import "regenerator-runtime/runtime";

import * as coinbase from "@shapeshiftoss/hdwallet-coinbase";
import { CoinbaseProviderConfig } from "@shapeshiftoss/hdwallet-coinbase";
import * as core from "@shapeshiftoss/hdwallet-core";
import * as keepkey from "@shapeshiftoss/hdwallet-keepkey";
import * as keepkeyTcp from "@shapeshiftoss/hdwallet-keepkey-tcp";
Expand Down Expand Up @@ -76,6 +78,14 @@ const walletConnectOptions: WalletConnectProviderConfig = {
},
};

const coinbaseOptions: CoinbaseProviderConfig = {
appName: "ShapeShift Sandbox",
appLogoUrl: "https://shapeshift.com/favicon.ico",
defaultJsonRpcUrl: "https://avatars.githubusercontent.com/u/52928763?s=50&v=4",
defaultChainId: 1,
darkMode: false,
};

const testPublicWalletXpubs = [
"xpub661MyMwAqRbcFLgDU7wpcEVubSF7NkswwmXBUkDiGUW6uopeUMys4AqKXNgpfZKRTLnpKQgffd6a2c3J8JxLkF1AQN17Pm9QYHEqEfo1Rsx", // all seed root key
"xpub68Zyu13qjcQxDzLNfTYnUXtJuX2qJgnxP6osrcAvJGdo6bs9M2Adt2BunbwiYrZS5qpA1QKoMf3uqS2NHpbyZp4KMJxDrL58NTyvHXBeAv6", // all seed m/44'
Expand All @@ -91,6 +101,7 @@ const testPublicWalletXpubs = [
"xpub6DDUPHpUo4pcy43iJeZjbSVWGav1SMMmuWdMHiGtkK8rhKmfbomtkwW6GKs1GGAKehT6QRocrmda3WWxXawpjmwaUHfFRXuKrXSapdckEYF", // all seed m/84'/0'/0'
].join(" ");

const coinbaseAdapter = coinbase.CoinbaseAdapter.useKeyring(keyring, coinbaseOptions);
const keepkeyAdapter = keepkeyWebUSB.WebUSBKeepKeyAdapter.useKeyring(keyring);
const kkbridgeAdapter = keepkeyTcp.TCPKeepKeyAdapter.useKeyring(keyring);
const kkemuAdapter = keepkeyTcp.TCPKeepKeyAdapter.useKeyring(keyring);
Expand Down Expand Up @@ -127,6 +138,7 @@ const $ledgerwebhid = $("#ledgerwebhid");
const $portis = $("#portis");
const $native = $("#native");
const $metaMask = $("#metaMask");
const $coinbase = $("#coinbase");
const $tallyHo = $("#tallyHo");
const $walletConnect = $("#walletConnect");
const $xdefi = $("#xdefi");
Expand Down Expand Up @@ -219,6 +231,19 @@ $metaMask.on("click", async (e) => {
}
});

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

$keplr.on("click", async (e) => {
e.preventDefault();
wallet = await keplrAdapter.pairDevice();
Expand Down Expand Up @@ -364,6 +389,12 @@ async function deviceConnected(deviceId) {
console.error("Could not initialize KeplrAdapter", e);
}

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

try {
await walletConnectAdapter.initialize();
} catch (e) {
Expand Down
32 changes: 16 additions & 16 deletions examples/sandbox/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "hdwallet-sandbox",
"version": "1.50.3",
"version": "1.50.4",
"license": "MIT",
"private": true,
"browserslist": "> 0.5%, last 2 versions, not dead",
Expand All @@ -10,21 +10,21 @@
"clean": "rm -rf public .parcel-cache"
},
"dependencies": {
"@shapeshiftoss/hdwallet-core": "1.50.3",
"@shapeshiftoss/hdwallet-keepkey-tcp": "1.50.3",
"@shapeshiftoss/hdwallet-keepkey-webusb": "1.50.3",
"@shapeshiftoss/hdwallet-keplr": "1.50.3",
"@shapeshiftoss/hdwallet-ledger": "1.50.3",
"@shapeshiftoss/hdwallet-ledger-webhid": "1.50.3",
"@shapeshiftoss/hdwallet-ledger-webusb": "1.50.3",
"@shapeshiftoss/hdwallet-metamask": "1.50.3",
"@shapeshiftoss/hdwallet-native": "1.50.3",
"@shapeshiftoss/hdwallet-portis": "1.50.3",
"@shapeshiftoss/hdwallet-tallyho": "1.50.3",
"@shapeshiftoss/hdwallet-trezor": "1.50.3",
"@shapeshiftoss/hdwallet-trezor-connect": "1.50.3",
"@shapeshiftoss/hdwallet-walletconnect": "1.50.3",
"@shapeshiftoss/hdwallet-xdefi": "1.50.3",
"@shapeshiftoss/hdwallet-core": "1.50.4",
"@shapeshiftoss/hdwallet-keepkey-tcp": "1.50.4",
"@shapeshiftoss/hdwallet-keepkey-webusb": "1.50.4",
"@shapeshiftoss/hdwallet-keplr": "1.50.4",
"@shapeshiftoss/hdwallet-ledger": "1.50.4",
"@shapeshiftoss/hdwallet-ledger-webhid": "1.50.4",
"@shapeshiftoss/hdwallet-ledger-webusb": "1.50.4",
"@shapeshiftoss/hdwallet-metamask": "1.50.4",
"@shapeshiftoss/hdwallet-native": "1.50.4",
"@shapeshiftoss/hdwallet-portis": "1.50.4",
"@shapeshiftoss/hdwallet-tallyho": "1.50.4",
"@shapeshiftoss/hdwallet-trezor": "1.50.4",
"@shapeshiftoss/hdwallet-trezor-connect": "1.50.4",
"@shapeshiftoss/hdwallet-walletconnect": "1.50.4",
"@shapeshiftoss/hdwallet-xdefi": "1.50.4",
"bip32": "^2.0.4",
"jquery": "^3.4.1",
"json": "^9.0.6",
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.50.3",
"version": "1.50.4",
"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.50.3",
"@shapeshiftoss/hdwallet-keepkey": "1.50.3",
"@shapeshiftoss/hdwallet-keepkey-nodewebusb": "1.50.3",
"@shapeshiftoss/hdwallet-keepkey-tcp": "1.50.3",
"@shapeshiftoss/hdwallet-ledger": "1.50.3",
"@shapeshiftoss/hdwallet-native": "1.50.3",
"@shapeshiftoss/hdwallet-portis": "1.50.3",
"@shapeshiftoss/hdwallet-trezor": "1.50.3",
"@shapeshiftoss/hdwallet-xdefi": "1.50.3",
"@shapeshiftoss/hdwallet-core": "1.50.4",
"@shapeshiftoss/hdwallet-keepkey": "1.50.4",
"@shapeshiftoss/hdwallet-keepkey-nodewebusb": "1.50.4",
"@shapeshiftoss/hdwallet-keepkey-tcp": "1.50.4",
"@shapeshiftoss/hdwallet-ledger": "1.50.4",
"@shapeshiftoss/hdwallet-native": "1.50.4",
"@shapeshiftoss/hdwallet-portis": "1.50.4",
"@shapeshiftoss/hdwallet-trezor": "1.50.4",
"@shapeshiftoss/hdwallet-xdefi": "1.50.4",
"@types/jest": "^26.0.23",
"fast-json-stable-stringify": "^2.1.0",
"jest": "^26.6.3",
Expand Down
2 changes: 1 addition & 1 deletion lerna.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"lerna": "3.22.1",
"version": "1.50.3",
"version": "1.50.4",
"npmClient": "yarn",
"useWorkspaces": true,
"command": {
Expand Down
26 changes: 26 additions & 0 deletions packages/hdwallet-coinbase/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"name": "@shapeshiftoss/hdwallet-coinbase",
"version": "1.50.4",
"license": "MIT",
"publishConfig": {
"access": "public"
},
"main": "dist/index.js",
"source": "src/index.ts",
"types": "dist/index.d.ts",
"scripts": {
"build": "tsc --build",
"clean": "rm -rf dist tsconfig.tsbuildinfo",
"prepublishOnly": "yarn clean && yarn build"
},
"dependencies": {
"@coinbase/wallet-sdk": "^3.6.6",
"@shapeshiftoss/hdwallet-core": "1.50.4",
"eth-rpc-errors": "^4.0.3",
"lodash": "^4.17.21"
},
"devDependencies": {
"@types/lodash": "^4.14.168",
"typescript": "^4.3.2"
}
}
62 changes: 62 additions & 0 deletions packages/hdwallet-coinbase/src/adapter.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import CoinbaseWalletSDK from "@coinbase/wallet-sdk";
import * as core from "@shapeshiftoss/hdwallet-core";

import { CoinbaseHDWallet } from "./coinbase";

export type CoinbaseProviderConfig = {
appName: string;
appLogoUrl: string;
defaultJsonRpcUrl: string;
defaultChainId: number;
darkMode: boolean;
};

export class CoinbaseAdapter {
keyring: core.Keyring;
providerConfig: CoinbaseProviderConfig;

private constructor(keyring: core.Keyring, config: CoinbaseProviderConfig) {
this.keyring = keyring;
this.providerConfig = config;
}

public static useKeyring(keyring: core.Keyring, config: CoinbaseProviderConfig) {
return new CoinbaseAdapter(keyring, config);
}

public async initialize(): Promise<number> {
return Object.keys(this.keyring.wallets).length;
}

public async pairDevice(): Promise<CoinbaseHDWallet | undefined> {
console.info("coinbase-wallet: pairDevice");
// Initialize Coinbase Wallet SDK
const coinbaseWallet = new CoinbaseWalletSDK({
appName: this.providerConfig.appName,
appLogoUrl: this.providerConfig.appLogoUrl,
darkMode: this.providerConfig.darkMode,
});

// Initialize a Web3 Provider object
const coinbaseWalletProvider = coinbaseWallet.makeWeb3Provider(
this.providerConfig.defaultJsonRpcUrl,
this.providerConfig.defaultChainId
);

try {
await coinbaseWalletProvider.request?.({ method: "eth_requestAccounts" });
} catch (err) {
console.error("Could not get Coinbase accounts: ", err);
throw err;
}

const wallet = new CoinbaseHDWallet(coinbaseWalletProvider);
await wallet.initialize();
const deviceID = await wallet.getDeviceID();

this.keyring.add(wallet, deviceID);
this.keyring.emit(["Coinbase", deviceID, core.Events.CONNECT], deviceID);

return wallet;
}
}
Loading

1 comment on commit 3306a2d

@vercel
Copy link

@vercel vercel bot commented on 3306a2d Jun 13, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

hdwallet – ./

hdwallet-shapeshift.vercel.app
hdwallet-git-master-shapeshift.vercel.app

Please sign in to comment.