@dynamic-labs/ethereum 0.19.0-alpha.20 → 0.19.0-alpha.22

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,4 +1,36 @@
1
1
 
2
+ ## [0.19.0-alpha.22](https://github.com/dynamic-labs/DynamicAuth/compare/v0.19.0-alpha.21...v0.19.0-alpha.22) (2023-10-23)
3
+
4
+
5
+ ### ⚠ BREAKING CHANGES
6
+
7
+ * rename unlinkConnectedWallet to disconnectWallet (#3595)
8
+
9
+ ### Features
10
+
11
+ * rename unlinkConnectedWallet to disconnectWallet ([#3595](https://github.com/dynamic-labs/DynamicAuth/issues/3595)) ([ac4a59e](https://github.com/dynamic-labs/DynamicAuth/commit/ac4a59ee5e50814fdb4190f07f5905b0c1499c7d))
12
+
13
+
14
+ ### Bug Fixes
15
+
16
+ * add support for apple oauth ([#3568](https://github.com/dynamic-labs/DynamicAuth/issues/3568)) ([10455fd](https://github.com/dynamic-labs/DynamicAuth/commit/10455fd74f22c6a1d66409fc01650d6ec68c2156))
17
+ * only process oauth message coming from the expected origin ([#3653](https://github.com/dynamic-labs/DynamicAuth/issues/3653)) ([3bf48d4](https://github.com/dynamic-labs/DynamicAuth/commit/3bf48d4a61fa624c30ff11861e6f5db4c33ef5c3))
18
+ * **SignMessagePreview:** safely render message to sign ([#3655](https://github.com/dynamic-labs/DynamicAuth/issues/3655)) ([02b520a](https://github.com/dynamic-labs/DynamicAuth/commit/02b520a2ddb6ba4042bf630de4cf80259c4fac37))
19
+
20
+ ## [0.19.0-alpha.21](https://github.com/dynamic-labs/DynamicAuth/compare/v0.19.0-alpha.20...v0.19.0-alpha.21) (2023-10-23)
21
+
22
+
23
+ ### ⚠ BREAKING CHANGES
24
+
25
+ * Restructure the SDK packages (#3623)
26
+
27
+ ### Features
28
+
29
+ * add support for overriding views ([#3649](https://github.com/dynamic-labs/DynamicAuth/issues/3649)) ([a722a1e](https://github.com/dynamic-labs/DynamicAuth/commit/a722a1e48d71373939e5f692bf215985959e1f0b))
30
+
31
+
32
+ * Restructure the SDK packages ([#3623](https://github.com/dynamic-labs/DynamicAuth/issues/3623)) ([aff5342](https://github.com/dynamic-labs/DynamicAuth/commit/aff5342f469a91b9092128daf74396c3af47f698))
33
+
2
34
  ## [0.19.0-alpha.20](https://github.com/dynamic-labs/DynamicAuth/compare/v0.19.0-alpha.19...v0.19.0-alpha.20) (2023-10-23)
3
35
 
4
36
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dynamic-labs/ethereum",
3
- "version": "0.19.0-alpha.20",
3
+ "version": "0.19.0-alpha.22",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/dynamic-labs/DynamicAuth.git",
@@ -26,16 +26,18 @@
26
26
  "./package.json": "./package.json"
27
27
  },
28
28
  "dependencies": {
29
+ "@coinbase/wallet-sdk": "3.6.4",
29
30
  "@walletconnect/client": "1.8.0",
30
31
  "@walletconnect/ethereum-provider": "1.8.0",
31
32
  "@walletconnect/universal-provider": "2.10.1",
32
33
  "eventemitter3": "5.0.1",
33
34
  "buffer": "6.0.3",
34
- "@dynamic-labs/rpc-providers": "0.19.0-alpha.20",
35
- "@dynamic-labs/types": "0.19.0-alpha.20",
36
- "@dynamic-labs/utils": "0.19.0-alpha.20",
37
- "@dynamic-labs/wallet-book": "0.19.0-alpha.20",
38
- "@dynamic-labs/wallet-connector-core": "0.19.0-alpha.20",
35
+ "@dynamic-labs/rpc-providers": "0.19.0-alpha.22",
36
+ "@dynamic-labs/turnkey": "0.19.0-alpha.22",
37
+ "@dynamic-labs/types": "0.19.0-alpha.22",
38
+ "@dynamic-labs/utils": "0.19.0-alpha.22",
39
+ "@dynamic-labs/wallet-book": "0.19.0-alpha.22",
40
+ "@dynamic-labs/wallet-connector-core": "0.19.0-alpha.22",
39
41
  "stream": "0.0.2"
40
42
  },
41
43
  "peerDependencies": {
@@ -0,0 +1,76 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var _tslib = require('../../../_virtual/_tslib.cjs');
6
+ var walletSdk = require('@coinbase/wallet-sdk');
7
+ var viem = require('viem');
8
+ var utils = require('@dynamic-labs/utils');
9
+ var constants = require('../../constants.cjs');
10
+
11
+ const jsonRpcUrl = `https://mainnet.infura.io/v3/${constants.INFURA_ID}`;
12
+ const chainId = 1;
13
+ let coinbaseProvider;
14
+ const getCoinbaseProvider = ({ opts: { appLogoUrl, appName = '', evmNetworks = [] } = {}, handlers, }) => {
15
+ var _a, _b;
16
+ if (!coinbaseProvider) {
17
+ const coinbaseWalletSDK = new walletSdk.CoinbaseWalletSDK({
18
+ appLogoUrl,
19
+ appName,
20
+ eventListener: {
21
+ onEvent: (eventType) => {
22
+ if (eventType === 'walletlink_sdk.disconnected') {
23
+ handlers === null || handlers === void 0 ? void 0 : handlers.onDisconnect();
24
+ }
25
+ },
26
+ },
27
+ headlessMode: true,
28
+ });
29
+ const network = evmNetworks === null || evmNetworks === void 0 ? void 0 : evmNetworks.find((network) => network.chainId === chainId);
30
+ const rpcUrl = ((_a = network === null || network === void 0 ? void 0 : network.privateCustomerRpcUrls) === null || _a === void 0 ? void 0 : _a[0]) ||
31
+ ((_b = network === null || network === void 0 ? void 0 : network.rpcUrls) === null || _b === void 0 ? void 0 : _b[0]) ||
32
+ jsonRpcUrl;
33
+ coinbaseProvider = coinbaseWalletSDK.makeWeb3Provider(rpcUrl, chainId);
34
+ }
35
+ return coinbaseProvider;
36
+ };
37
+ const killCoinbaseSession = () => _tslib.__awaiter(void 0, void 0, void 0, function* () {
38
+ if (coinbaseProvider) {
39
+ coinbaseProvider.close();
40
+ coinbaseProvider.disconnect();
41
+ }
42
+ });
43
+ const fetchPublicAddress = (coinbaseProviderOpts, opts) => _tslib.__awaiter(void 0, void 0, void 0, function* () {
44
+ var _a;
45
+ const provider = getCoinbaseProvider({ opts: coinbaseProviderOpts });
46
+ const { qrUrl } = provider;
47
+ if (!qrUrl) {
48
+ throw new utils.DynamicError('no qr url available');
49
+ }
50
+ (_a = opts === null || opts === void 0 ? void 0 : opts.onDisplayUri) === null || _a === void 0 ? void 0 : _a.call(opts, qrUrl);
51
+ const [address] = yield provider.request({
52
+ method: 'eth_requestAccounts',
53
+ });
54
+ return address;
55
+ });
56
+ const signMessage = (coinbaseProviderOpts, messageToSign) => _tslib.__awaiter(void 0, void 0, void 0, function* () {
57
+ const provider = getCoinbaseProvider({ opts: coinbaseProviderOpts });
58
+ const [address] = yield provider.request({
59
+ method: 'eth_requestAccounts',
60
+ });
61
+ try {
62
+ return yield provider.request({
63
+ method: 'personal_sign',
64
+ params: [viem.toHex(viem.toBytes(messageToSign)), address.toLowerCase()],
65
+ });
66
+ }
67
+ catch (err) {
68
+ yield provider.close();
69
+ return undefined;
70
+ }
71
+ });
72
+
73
+ exports.fetchPublicAddress = fetchPublicAddress;
74
+ exports.getCoinbaseProvider = getCoinbaseProvider;
75
+ exports.killCoinbaseSession = killCoinbaseSession;
76
+ exports.signMessage = signMessage;
@@ -0,0 +1,6 @@
1
+ import { FetchPublicAddressOpts } from '@dynamic-labs/wallet-connector-core';
2
+ import { GetCoinbaseProvider, GetCoinbaseProviderOpts } from './types';
3
+ export declare const getCoinbaseProvider: GetCoinbaseProvider;
4
+ export declare const killCoinbaseSession: () => Promise<void>;
5
+ export declare const fetchPublicAddress: (coinbaseProviderOpts: GetCoinbaseProviderOpts, opts?: FetchPublicAddressOpts) => Promise<string | undefined>;
6
+ export declare const signMessage: (coinbaseProviderOpts: GetCoinbaseProviderOpts, messageToSign: string) => Promise<string | undefined>;
@@ -0,0 +1,69 @@
1
+ import { __awaiter } from '../../../_virtual/_tslib.js';
2
+ import { CoinbaseWalletSDK } from '@coinbase/wallet-sdk';
3
+ import { toHex, toBytes } from 'viem';
4
+ import { DynamicError } from '@dynamic-labs/utils';
5
+ import { INFURA_ID } from '../../constants.js';
6
+
7
+ const jsonRpcUrl = `https://mainnet.infura.io/v3/${INFURA_ID}`;
8
+ const chainId = 1;
9
+ let coinbaseProvider;
10
+ const getCoinbaseProvider = ({ opts: { appLogoUrl, appName = '', evmNetworks = [] } = {}, handlers, }) => {
11
+ var _a, _b;
12
+ if (!coinbaseProvider) {
13
+ const coinbaseWalletSDK = new CoinbaseWalletSDK({
14
+ appLogoUrl,
15
+ appName,
16
+ eventListener: {
17
+ onEvent: (eventType) => {
18
+ if (eventType === 'walletlink_sdk.disconnected') {
19
+ handlers === null || handlers === void 0 ? void 0 : handlers.onDisconnect();
20
+ }
21
+ },
22
+ },
23
+ headlessMode: true,
24
+ });
25
+ const network = evmNetworks === null || evmNetworks === void 0 ? void 0 : evmNetworks.find((network) => network.chainId === chainId);
26
+ const rpcUrl = ((_a = network === null || network === void 0 ? void 0 : network.privateCustomerRpcUrls) === null || _a === void 0 ? void 0 : _a[0]) ||
27
+ ((_b = network === null || network === void 0 ? void 0 : network.rpcUrls) === null || _b === void 0 ? void 0 : _b[0]) ||
28
+ jsonRpcUrl;
29
+ coinbaseProvider = coinbaseWalletSDK.makeWeb3Provider(rpcUrl, chainId);
30
+ }
31
+ return coinbaseProvider;
32
+ };
33
+ const killCoinbaseSession = () => __awaiter(void 0, void 0, void 0, function* () {
34
+ if (coinbaseProvider) {
35
+ coinbaseProvider.close();
36
+ coinbaseProvider.disconnect();
37
+ }
38
+ });
39
+ const fetchPublicAddress = (coinbaseProviderOpts, opts) => __awaiter(void 0, void 0, void 0, function* () {
40
+ var _a;
41
+ const provider = getCoinbaseProvider({ opts: coinbaseProviderOpts });
42
+ const { qrUrl } = provider;
43
+ if (!qrUrl) {
44
+ throw new DynamicError('no qr url available');
45
+ }
46
+ (_a = opts === null || opts === void 0 ? void 0 : opts.onDisplayUri) === null || _a === void 0 ? void 0 : _a.call(opts, qrUrl);
47
+ const [address] = yield provider.request({
48
+ method: 'eth_requestAccounts',
49
+ });
50
+ return address;
51
+ });
52
+ const signMessage = (coinbaseProviderOpts, messageToSign) => __awaiter(void 0, void 0, void 0, function* () {
53
+ const provider = getCoinbaseProvider({ opts: coinbaseProviderOpts });
54
+ const [address] = yield provider.request({
55
+ method: 'eth_requestAccounts',
56
+ });
57
+ try {
58
+ return yield provider.request({
59
+ method: 'personal_sign',
60
+ params: [toHex(toBytes(messageToSign)), address.toLowerCase()],
61
+ });
62
+ }
63
+ catch (err) {
64
+ yield provider.close();
65
+ return undefined;
66
+ }
67
+ });
68
+
69
+ export { fetchPublicAddress, getCoinbaseProvider, killCoinbaseSession, signMessage };
@@ -0,0 +1,2 @@
1
+ export * from './client';
2
+ export * from './types';
@@ -0,0 +1,14 @@
1
+ import { CoinbaseWalletProvider } from '@coinbase/wallet-sdk';
2
+ import { GenericNetwork } from '@dynamic-labs/types';
3
+ export type GetCoinbaseProviderOpts = {
4
+ appLogoUrl?: string;
5
+ appName?: string;
6
+ evmNetworks?: GenericNetwork[];
7
+ };
8
+ export type CoinbaseProviderHandlerOpts = {
9
+ onDisconnect(): Promise<void>;
10
+ };
11
+ export type GetCoinbaseProvider = (args: {
12
+ handlers?: CoinbaseProviderHandlerOpts;
13
+ opts?: GetCoinbaseProviderOpts;
14
+ }) => CoinbaseWalletProvider;
@@ -0,0 +1,71 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var _tslib = require('../../_virtual/_tslib.cjs');
6
+ var viem = require('viem');
7
+ var EthWalletConnector = require('../EthWalletConnector.cjs');
8
+ var legacyEthProviderHelper = require('../legacyEthProviderHelper.cjs');
9
+ var client = require('./client/client.cjs');
10
+
11
+ class Coinbase extends EthWalletConnector.EthWalletConnector {
12
+ constructor(_a) {
13
+ var { appName, appLogoUrl, evmNetworks } = _a, props = _tslib.__rest(_a, ["appName", "appLogoUrl", "evmNetworks"]);
14
+ super(Object.assign({ evmNetworks }, props));
15
+ this.name = 'Coinbase';
16
+ this.supportedChains = ['EVM', 'ETH'];
17
+ this.connectedChain = 'EVM';
18
+ this.canConnectViaQrCode = true;
19
+ this.coinbaseProviderOpts = {
20
+ appLogoUrl: appLogoUrl,
21
+ appName: appName,
22
+ evmNetworks: evmNetworks,
23
+ };
24
+ }
25
+ setupEventListeners() {
26
+ const provider = legacyEthProviderHelper.LegacyEthProviderHelper.findProvider(this.name);
27
+ if (!provider) {
28
+ return;
29
+ }
30
+ const { tearDownEventListeners } = legacyEthProviderHelper.LegacyEthProviderHelper._setupEventListeners(this.name, this, viem.createPublicClient({ transport: viem.custom(provider) }));
31
+ this.teardownEventListeners = tearDownEventListeners;
32
+ }
33
+ getWalletClient() {
34
+ if (this.isInstalledOnBrowser()) {
35
+ return legacyEthProviderHelper.LegacyEthProviderHelper.findWalletClient(this.name);
36
+ }
37
+ return viem.createWalletClient({
38
+ transport: viem.custom(client.getCoinbaseProvider({
39
+ opts: this.coinbaseProviderOpts,
40
+ })),
41
+ });
42
+ }
43
+ isInstalledOnBrowser() {
44
+ return legacyEthProviderHelper.LegacyEthProviderHelper.isInstalledHelper(this.name);
45
+ }
46
+ fetchPublicAddress(opts) {
47
+ return _tslib.__awaiter(this, void 0, void 0, function* () {
48
+ if (this.isInstalledOnBrowser()) {
49
+ return legacyEthProviderHelper.LegacyEthProviderHelper.fetchPublicAddressWithName(this.name);
50
+ }
51
+ return client.fetchPublicAddress(this.coinbaseProviderOpts, opts);
52
+ });
53
+ }
54
+ signMessage(messageToSign) {
55
+ return _tslib.__awaiter(this, void 0, void 0, function* () {
56
+ if (this.isInstalledOnBrowser()) {
57
+ return legacyEthProviderHelper.LegacyEthProviderHelper.signMessageWithName(messageToSign, this.name);
58
+ }
59
+ return client.signMessage(this.coinbaseProviderOpts, messageToSign);
60
+ });
61
+ }
62
+ endSession() {
63
+ return _tslib.__awaiter(this, void 0, void 0, function* () {
64
+ if (this.isInstalledOnBrowser())
65
+ return;
66
+ client.killCoinbaseSession();
67
+ });
68
+ }
69
+ }
70
+
71
+ exports.Coinbase = Coinbase;