-
Notifications
You must be signed in to change notification settings - Fork 91
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 #624 from shapeshift/coinbase-wallet
- Loading branch information
Showing
35 changed files
with
1,178 additions
and
90 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
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" | ||
} | ||
} |
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,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; | ||
} | ||
} |
Oops, something went wrong.
3306a2d
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.
Successfully deployed to the following URLs:
hdwallet – ./
hdwallet-shapeshift.vercel.app
hdwallet-git-master-shapeshift.vercel.app