@dynamic-labs/ethereum 2.1.0-alpha.1 → 2.1.0-alpha.10

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.
@@ -1,73 +0,0 @@
1
- 'use client'
2
- 'use strict';
3
-
4
- Object.defineProperty(exports, '__esModule', { value: true });
5
-
6
- var _tslib = require('../../../_virtual/_tslib.cjs');
7
- var walletSdk = require('@coinbase/wallet-sdk');
8
- var viem = require('viem');
9
- var utils = require('@dynamic-labs/utils');
10
- var constants = require('../../constants.cjs');
11
-
12
- const jsonRpcUrl = `https://mainnet.infura.io/v3/${constants.INFURA_ID}`;
13
- const chainId = 1;
14
- // storing a reference to the coinbase sdk so that we can call getQrUrl on it when we need a fresh qr code
15
- let coinbaseSdk;
16
- // storing a reference to the coinbase provider because the provider methods work better when
17
- // they are called on the same instance
18
- let coinbaseProvider;
19
- const getCoinbaseClient = ({ opts: { appLogoUrl, appName = '', evmNetworks = [] } = {}, }) => {
20
- var _a, _b;
21
- if (!coinbaseProvider) {
22
- coinbaseSdk = new walletSdk.CoinbaseWalletSDK({
23
- appLogoUrl,
24
- appName,
25
- enableMobileWalletLink: true,
26
- headlessMode: true,
27
- reloadOnDisconnect: false,
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 = coinbaseSdk.makeWeb3Provider(rpcUrl, chainId);
34
- }
35
- return { provider: coinbaseProvider, sdk: coinbaseSdk };
36
- };
37
- const killCoinbaseSession = () => _tslib.__awaiter(void 0, void 0, void 0, function* () {
38
- yield (coinbaseProvider === null || coinbaseProvider === void 0 ? void 0 : coinbaseProvider.close());
39
- });
40
- const getAddress = (coinbaseProviderOpts, opts) => _tslib.__awaiter(void 0, void 0, void 0, function* () {
41
- var _a;
42
- const { provider, sdk } = getCoinbaseClient({ opts: coinbaseProviderOpts });
43
- const qrUrl = sdk.getQrUrl();
44
- if (!qrUrl) {
45
- throw new utils.DynamicError('no qr url available');
46
- }
47
- (_a = opts === null || opts === void 0 ? void 0 : opts.onDisplayUri) === null || _a === void 0 ? void 0 : _a.call(opts, qrUrl);
48
- const [address] = yield provider.request({
49
- method: 'eth_requestAccounts',
50
- });
51
- return address;
52
- });
53
- const signMessage = (coinbaseProviderOpts, messageToSign) => _tslib.__awaiter(void 0, void 0, void 0, function* () {
54
- const { provider } = getCoinbaseClient({ opts: coinbaseProviderOpts });
55
- const [address] = yield provider.request({
56
- method: 'eth_requestAccounts',
57
- });
58
- try {
59
- return yield provider.request({
60
- method: 'personal_sign',
61
- params: [viem.toHex(viem.toBytes(messageToSign)), address.toLowerCase()],
62
- });
63
- }
64
- catch (err) {
65
- yield provider.close();
66
- return undefined;
67
- }
68
- });
69
-
70
- exports.getAddress = getAddress;
71
- exports.getCoinbaseClient = getCoinbaseClient;
72
- exports.killCoinbaseSession = killCoinbaseSession;
73
- exports.signMessage = signMessage;
@@ -1,7 +0,0 @@
1
- import { GetAddressOpts } from '@dynamic-labs/wallet-connector-core';
2
- import { GetCoinbaseClient, GetCoinbaseProviderOpts } from './types';
3
- export declare const clearClientVariables: () => void;
4
- export declare const getCoinbaseClient: GetCoinbaseClient;
5
- export declare const killCoinbaseSession: () => Promise<void>;
6
- export declare const getAddress: (coinbaseProviderOpts: GetCoinbaseProviderOpts, opts?: GetAddressOpts) => Promise<string | undefined>;
7
- export declare const signMessage: (coinbaseProviderOpts: GetCoinbaseProviderOpts, messageToSign: string) => Promise<string | undefined>;
@@ -1,66 +0,0 @@
1
- 'use client'
2
- import { __awaiter } from '../../../_virtual/_tslib.js';
3
- import { CoinbaseWalletSDK } from '@coinbase/wallet-sdk';
4
- import { toHex, toBytes } from 'viem';
5
- import { DynamicError } from '@dynamic-labs/utils';
6
- import { INFURA_ID } from '../../constants.js';
7
-
8
- const jsonRpcUrl = `https://mainnet.infura.io/v3/${INFURA_ID}`;
9
- const chainId = 1;
10
- // storing a reference to the coinbase sdk so that we can call getQrUrl on it when we need a fresh qr code
11
- let coinbaseSdk;
12
- // storing a reference to the coinbase provider because the provider methods work better when
13
- // they are called on the same instance
14
- let coinbaseProvider;
15
- const getCoinbaseClient = ({ opts: { appLogoUrl, appName = '', evmNetworks = [] } = {}, }) => {
16
- var _a, _b;
17
- if (!coinbaseProvider) {
18
- coinbaseSdk = new CoinbaseWalletSDK({
19
- appLogoUrl,
20
- appName,
21
- enableMobileWalletLink: true,
22
- headlessMode: true,
23
- reloadOnDisconnect: false,
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 = coinbaseSdk.makeWeb3Provider(rpcUrl, chainId);
30
- }
31
- return { provider: coinbaseProvider, sdk: coinbaseSdk };
32
- };
33
- const killCoinbaseSession = () => __awaiter(void 0, void 0, void 0, function* () {
34
- yield (coinbaseProvider === null || coinbaseProvider === void 0 ? void 0 : coinbaseProvider.close());
35
- });
36
- const getAddress = (coinbaseProviderOpts, opts) => __awaiter(void 0, void 0, void 0, function* () {
37
- var _a;
38
- const { provider, sdk } = getCoinbaseClient({ opts: coinbaseProviderOpts });
39
- const qrUrl = sdk.getQrUrl();
40
- if (!qrUrl) {
41
- throw new DynamicError('no qr url available');
42
- }
43
- (_a = opts === null || opts === void 0 ? void 0 : opts.onDisplayUri) === null || _a === void 0 ? void 0 : _a.call(opts, qrUrl);
44
- const [address] = yield provider.request({
45
- method: 'eth_requestAccounts',
46
- });
47
- return address;
48
- });
49
- const signMessage = (coinbaseProviderOpts, messageToSign) => __awaiter(void 0, void 0, void 0, function* () {
50
- const { provider } = getCoinbaseClient({ opts: coinbaseProviderOpts });
51
- const [address] = yield provider.request({
52
- method: 'eth_requestAccounts',
53
- });
54
- try {
55
- return yield provider.request({
56
- method: 'personal_sign',
57
- params: [toHex(toBytes(messageToSign)), address.toLowerCase()],
58
- });
59
- }
60
- catch (err) {
61
- yield provider.close();
62
- return undefined;
63
- }
64
- });
65
-
66
- export { getAddress, getCoinbaseClient, killCoinbaseSession, signMessage };
@@ -1,2 +0,0 @@
1
- export * from './client';
2
- export * from './types';
@@ -1,17 +0,0 @@
1
- import CoinbaseWalletSDK, { 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 GetCoinbaseClient = (args: {
12
- handlers?: CoinbaseProviderHandlerOpts;
13
- opts?: GetCoinbaseProviderOpts;
14
- }) => {
15
- provider: CoinbaseWalletProvider;
16
- sdk: CoinbaseWalletSDK;
17
- };