@coinbase/wallet-sdk
Advanced tools
Comparing version 4.0.0-beta.7 to 4.0.0-beta.8
@@ -5,3 +5,3 @@ import EventEmitter from 'eventemitter3'; | ||
import { RequestHandler } from './core/type/RequestHandlerInterface'; | ||
import { AccountsUpdate, ChainUpdate } from './sign/UpdateListenerInterface'; | ||
import { AccountsUpdate, ChainUpdate } from './sign/interface'; | ||
export declare class CoinbaseWalletProvider extends EventEmitter implements ProviderInterface { | ||
@@ -11,4 +11,2 @@ protected accounts: AddressString[]; | ||
protected readonly handlers: RequestHandler[]; | ||
get chainId(): number; | ||
get isCoinbaseWallet(): boolean; | ||
constructor(options: Readonly<ConstructorOptions>); | ||
@@ -26,2 +24,3 @@ protected updateListener: { | ||
enable(): Promise<unknown>; | ||
readonly isCoinbaseWallet = true; | ||
private emitConnectEvent; | ||
@@ -28,0 +27,0 @@ private setAccounts; |
@@ -9,4 +9,4 @@ "use strict"; | ||
const eventemitter3_1 = __importDefault(require("eventemitter3")); | ||
const eip1193Utils_1 = require("./core/eip1193Utils"); | ||
const error_1 = require("./core/error"); | ||
const providerUtils_1 = require("./core/providerUtils"); | ||
const util_1 = require("./core/util"); | ||
@@ -18,8 +18,2 @@ const FilterRequestHandler_1 = require("./filter/FilterRequestHandler"); | ||
class CoinbaseWalletProvider extends eventemitter3_1.default { | ||
get chainId() { | ||
return this.chain.id; | ||
} | ||
get isCoinbaseWallet() { | ||
return true; | ||
} | ||
constructor(options) { | ||
@@ -35,8 +29,9 @@ var _a, _b; | ||
}; | ||
this.isCoinbaseWallet = true; | ||
this.chain = { | ||
id: (_b = (_a = options.appChainIds) === null || _a === void 0 ? void 0 : _a[0]) !== null && _b !== void 0 ? _b : 1, | ||
id: (_b = (_a = options.metadata.appChainIds) === null || _a === void 0 ? void 0 : _a[0]) !== null && _b !== void 0 ? _b : 1, | ||
}; | ||
this.handlers = [ | ||
new SignRequestHandler_1.SignRequestHandler(Object.assign(Object.assign({}, options), { updateListener: this.updateListener })), | ||
new StateRequestHandler_1.StateRequestHandler(), | ||
new SignRequestHandler_1.SignRequestHandler(Object.assign(Object.assign({}, options), { updateListener: this.updateListener })), | ||
new FilterRequestHandler_1.FilterRequestHandler({ | ||
@@ -62,3 +57,3 @@ provider: this, | ||
async request(args) { | ||
const invalidArgsError = (0, eip1193Utils_1.getErrorForInvalidRequestArgs)(args); | ||
const invalidArgsError = (0, providerUtils_1.getErrorForInvalidRequestArgs)(args); | ||
if (invalidArgsError) { | ||
@@ -65,0 +60,0 @@ throw invalidArgsError; |
import { LogoType } from './assets/wallet-logo'; | ||
import { ConstructorOptions, ProviderInterface } from './core/type/ProviderInterface'; | ||
import { AppMetadata, Preference, ProviderInterface } from './core/type/ProviderInterface'; | ||
interface CoinbaseWalletSDKOptions extends Partial<AppMetadata> { | ||
preference?: Preference; | ||
} | ||
export declare class CoinbaseWalletSDK { | ||
private appName; | ||
private appLogoUrl; | ||
private smartWalletOnly; | ||
private chainIds; | ||
/** | ||
* Constructor | ||
* @param options Coinbase Wallet SDK constructor options | ||
*/ | ||
constructor(options: Readonly<Partial<ConstructorOptions>>); | ||
private storeLatestVersion; | ||
private options; | ||
constructor(options: Readonly<CoinbaseWalletSDKOptions>); | ||
makeWeb3Provider(): ProviderInterface; | ||
@@ -22,5 +17,4 @@ /** | ||
getCoinbaseWalletLogo(type: LogoType, width?: number): string; | ||
private get walletExtension(); | ||
private get walletExtensionSigner(); | ||
private get coinbaseBrowser(); | ||
private storeLatestVersion; | ||
} | ||
export {}; |
@@ -8,43 +8,26 @@ "use strict"; | ||
const ScopedLocalStorage_1 = require("./core/storage/ScopedLocalStorage"); | ||
const version_1 = require("./version"); | ||
const providerUtils_1 = require("./core/providerUtils"); | ||
const util_1 = require("./core/util"); | ||
const version_1 = require("./version"); | ||
class CoinbaseWalletSDK { | ||
/** | ||
* Constructor | ||
* @param options Coinbase Wallet SDK constructor options | ||
*/ | ||
constructor(options) { | ||
var _a, _b; | ||
this.smartWalletOnly = options.smartWalletOnly || false; | ||
this.chainIds = (_b = (_a = options.appChainIds) === null || _a === void 0 ? void 0 : _a.map(Number)) !== null && _b !== void 0 ? _b : []; | ||
this.appName = options.appName || 'DApp'; | ||
this.appLogoUrl = options.appLogoUrl || (0, util_1.getFavicon)(); | ||
this.options = options; | ||
this.storeLatestVersion(); | ||
} | ||
storeLatestVersion() { | ||
const versionStorage = new ScopedLocalStorage_1.ScopedLocalStorage('CBWSDK'); | ||
versionStorage.setItem('VERSION', version_1.LIB_VERSION); | ||
} | ||
makeWeb3Provider() { | ||
var _a; | ||
if (!this.smartWalletOnly) { | ||
const extensionProvider = this.walletExtension; | ||
const shouldUseExtensionProvider = extensionProvider && !this.walletExtensionSigner; | ||
if (shouldUseExtensionProvider) { | ||
if ('setAppInfo' in extensionProvider && | ||
typeof extensionProvider.setAppInfo === 'function') { | ||
(_a = extensionProvider.setAppInfo) === null || _a === void 0 ? void 0 : _a.call(extensionProvider, this.appName, this.appLogoUrl); | ||
} | ||
return extensionProvider; | ||
const { appName = 'Dapp', appLogoUrl = (0, util_1.getFavicon)(), appChainIds = [], preference = { options: 'all' }, } = this.options; | ||
const provider = (0, providerUtils_1.fetchCoinbaseInjectedProvider)(preference.options === 'smartWalletOnly'); | ||
if (provider) { | ||
if ('setAppInfo' in provider && typeof provider.setAppInfo === 'function') { | ||
provider.setAppInfo(appName, appLogoUrl); | ||
} | ||
return provider; | ||
} | ||
const dappBrowser = this.coinbaseBrowser; | ||
if (dappBrowser) { | ||
return dappBrowser; | ||
} | ||
return new CoinbaseWalletProvider_1.CoinbaseWalletProvider({ | ||
appName: this.appName, | ||
appLogoUrl: this.appLogoUrl, | ||
appChainIds: this.chainIds, | ||
smartWalletOnly: this.smartWalletOnly, | ||
metadata: { | ||
appName, | ||
appLogoUrl, | ||
appChainIds, | ||
}, | ||
preference, | ||
}); | ||
@@ -61,26 +44,7 @@ } | ||
} | ||
get walletExtension() { | ||
return window.coinbaseWalletExtension; | ||
storeLatestVersion() { | ||
const versionStorage = new ScopedLocalStorage_1.ScopedLocalStorage('CBWSDK'); | ||
versionStorage.setItem('VERSION', version_1.LIB_VERSION); | ||
} | ||
get walletExtensionSigner() { | ||
return window.coinbaseWalletExtensionSigner; | ||
} | ||
get coinbaseBrowser() { | ||
var _a, _b; | ||
try { | ||
// Coinbase DApp browser does not inject into iframes so grab provider from top frame if it exists | ||
const ethereum = (_a = window.ethereum) !== null && _a !== void 0 ? _a : (_b = window.top) === null || _b === void 0 ? void 0 : _b.ethereum; | ||
if (!ethereum) { | ||
return undefined; | ||
} | ||
if ('isCoinbaseBrowser' in ethereum && ethereum.isCoinbaseBrowser) { | ||
return ethereum; | ||
} | ||
return undefined; | ||
} | ||
catch (e) { | ||
return undefined; | ||
} | ||
} | ||
} | ||
exports.CoinbaseWalletSDK = CoinbaseWalletSDK; |
@@ -1,7 +0,5 @@ | ||
import { Message } from '../message'; | ||
import { Message, MessageWithOptionalId } from '../message'; | ||
export declare abstract class CrossDomainCommunicator { | ||
protected url: URL | undefined; | ||
protected _connected: boolean; | ||
get connected(): boolean; | ||
protected set connected(value: boolean); | ||
private connected; | ||
protected abstract onConnect(): Promise<void>; | ||
@@ -13,5 +11,10 @@ protected abstract onDisconnect(): void; | ||
protected peerWindow: Window | null; | ||
postMessage(message: Message, options?: { | ||
private getTargetOrigin; | ||
postMessage<M extends Message>(params: MessageWithOptionalId<M>, options?: { | ||
bypassTargetOriginCheck: boolean; | ||
}): void; | ||
postMessageForResponse<M extends Message>(params: MessageWithOptionalId<M>): Promise<Message>; | ||
private requestMap; | ||
private eventListener; | ||
private rejectWaitingRequests; | ||
} |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.CrossDomainCommunicator = void 0; | ||
const message_1 = require("../message"); | ||
const error_1 = require("../error"); | ||
@@ -8,36 +9,64 @@ class CrossDomainCommunicator { | ||
this.url = undefined; | ||
this._connected = false; | ||
this.connected = false; | ||
this.peerWindow = null; | ||
this.requestMap = new Map(); | ||
} | ||
get connected() { | ||
return this._connected; | ||
} | ||
set connected(value) { | ||
this._connected = value; | ||
} | ||
async connect() { | ||
window.addEventListener('message', this.onEvent.bind(this)); | ||
if (this.connected) | ||
return; | ||
window.addEventListener('message', this.eventListener.bind(this)); | ||
await this.onConnect(); | ||
this.connected = true; | ||
} | ||
disconnect() { | ||
this.connected = false; | ||
window.removeEventListener('message', this.eventListener.bind(this)); | ||
this.rejectWaitingRequests(); | ||
this.onDisconnect(); | ||
} | ||
postMessage(message, options) { | ||
var _a; | ||
let targetOrigin = (_a = this.url) === null || _a === void 0 ? void 0 : _a.origin; | ||
if (targetOrigin === undefined) { | ||
if (options === null || options === void 0 ? void 0 : options.bypassTargetOriginCheck) { | ||
targetOrigin = '*'; | ||
} | ||
else { | ||
throw error_1.standardErrors.rpc.internal('Communicator: No target origin'); | ||
} | ||
} | ||
if (!this.peerWindow) { | ||
getTargetOrigin(options) { | ||
if (this.url) | ||
return this.url.origin; | ||
if (options === null || options === void 0 ? void 0 : options.bypassTargetOriginCheck) | ||
return '*'; | ||
return undefined; | ||
} | ||
postMessage(params, options) { | ||
const targetOrigin = this.getTargetOrigin(options); | ||
if (!targetOrigin || !this.peerWindow) { | ||
throw error_1.standardErrors.rpc.internal('Communicator: No peer window found'); | ||
} | ||
const message = (0, message_1.createMessage)(params); | ||
this.peerWindow.postMessage(message, targetOrigin); | ||
} | ||
async postMessageForResponse(params) { | ||
return new Promise((resolve, reject) => { | ||
const message = (0, message_1.createMessage)(params); | ||
this.requestMap.set(message.id, { | ||
resolve, | ||
reject, | ||
}); | ||
this.postMessage(params); | ||
}); | ||
} | ||
eventListener(event) { | ||
var _a, _b, _c; | ||
if (event.origin !== ((_a = this.url) === null || _a === void 0 ? void 0 : _a.origin)) | ||
return; | ||
const message = event.data; | ||
const { requestId } = message; | ||
if (!requestId) { | ||
this.onEvent(event); | ||
return; | ||
} | ||
(_c = (_b = this.requestMap.get(requestId)) === null || _b === void 0 ? void 0 : _b.resolve) === null || _c === void 0 ? void 0 : _c.call(_b, message); | ||
this.requestMap.delete(requestId); | ||
} | ||
rejectWaitingRequests() { | ||
this.requestMap.forEach(({ reject }) => { | ||
reject(error_1.standardErrors.provider.userRejectedRequest('Request rejected')); | ||
}); | ||
this.requestMap.clear(); | ||
} | ||
} | ||
exports.CrossDomainCommunicator = CrossDomainCommunicator; |
export declare const CB_KEYS_URL = "https://keys.coinbase.com/connect"; | ||
export declare const CB_KEYS_BACKEND_URL = "https://api.wallet.coinbase.com/rpc/v3/scw/sdk-proxy"; | ||
export declare const WALLETLINK_URL = "https://www.walletlink.org"; | ||
export declare const CBW_MOBILE_DEEPLINK_URL = "https://go.cb-w.com/walletlink"; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.CBW_MOBILE_DEEPLINK_URL = exports.WALLETLINK_URL = exports.CB_KEYS_BACKEND_URL = exports.CB_KEYS_URL = void 0; | ||
exports.CBW_MOBILE_DEEPLINK_URL = exports.WALLETLINK_URL = exports.CB_KEYS_URL = void 0; | ||
exports.CB_KEYS_URL = 'https://keys.coinbase.com/connect'; | ||
exports.CB_KEYS_BACKEND_URL = 'https://api.wallet.coinbase.com/rpc/v3/scw/sdk-proxy'; | ||
exports.WALLETLINK_URL = 'https://www.walletlink.org'; | ||
exports.CBW_MOBILE_DEEPLINK_URL = 'https://go.cb-w.com/walletlink'; |
@@ -0,1 +1,2 @@ | ||
import { AppMetadata } from '../type/ProviderInterface'; | ||
export declare enum SupportedEthereumMethods { | ||
@@ -14,13 +15,7 @@ EthRequestAccounts = "eth_requestAccounts", | ||
WalletGetCapabilities = "wallet_getCapabilities", | ||
WalletSendCalls = "wallet_sendCalls", | ||
WalletGetCallsStatus = "wallet_getCallsStatus" | ||
WalletSendCalls = "wallet_sendCalls" | ||
} | ||
export type RequestAccountsAction = { | ||
method: SupportedEthereumMethods.EthRequestAccounts; | ||
params: { | ||
dappName: string; | ||
dappLogoUrl: string | null; | ||
dappOrigin?: string; | ||
chainIds?: number[]; | ||
}; | ||
params: AppMetadata; | ||
}; | ||
@@ -137,7 +132,3 @@ export type SignAction = { | ||
}; | ||
export type GetCallsStatusAction = { | ||
method: SupportedEthereumMethods.WalletGetCallsStatus; | ||
params: [string]; | ||
}; | ||
export type AllAction = RequestAccountsAction | SignAction | PersonalSignAction | SignTypedDataV1Action | SignTypedDataV3Action | SignTypedDataV4Action | SignTransactionAction | SendTransactionAction | SendRawTransactionAction | SwitchEthereumChainAction | AddEthereumChainAction | GetCapabilitiesAction | WalletSendCallsAction | GetCallsStatusAction; | ||
export type AllAction = RequestAccountsAction | SignAction | PersonalSignAction | SignTypedDataV1Action | SignTypedDataV3Action | SignTypedDataV4Action | SignTransactionAction | SendTransactionAction | SendRawTransactionAction | SwitchEthereumChainAction | AddEthereumChainAction | GetCapabilitiesAction | WalletSendCallsAction; | ||
export type Action = { | ||
@@ -144,0 +135,0 @@ method: SupportedEthereumMethods; |
@@ -22,3 +22,2 @@ "use strict"; | ||
SupportedEthereumMethods["WalletSendCalls"] = "wallet_sendCalls"; | ||
SupportedEthereumMethods["WalletGetCallsStatus"] = "wallet_getCallsStatus"; | ||
})(SupportedEthereumMethods || (exports.SupportedEthereumMethods = SupportedEthereumMethods = {})); |
@@ -1,23 +0,17 @@ | ||
import { Message } from '.'; | ||
export interface ConfigMessage extends Message { | ||
type: 'config'; | ||
event: { | ||
type: ClientConfigEventType | HostConfigEventType; | ||
value?: unknown; | ||
}; | ||
import { Message, MessageID } from '.'; | ||
export interface ConfigUpdateMessage extends Message { | ||
event: ConfigEvent; | ||
data?: unknown; | ||
} | ||
export declare enum ClientConfigEventType { | ||
SelectConnectionType = "selectConnectionType", | ||
DappOriginMessage = "dappOriginMessage", | ||
WalletLinkUrl = "walletLinkUrl", | ||
WalletLinkQrScanned = "walletLinkQrScanned" | ||
export declare function isConfigUpdateMessage(message: Message): message is ConfigUpdateMessage; | ||
export interface ConfigResponseMessage extends Message { | ||
requestId: MessageID; | ||
data?: unknown; | ||
} | ||
export declare enum HostConfigEventType { | ||
PopupListenerAdded = "popupListenerAdded", | ||
PopupReadyForRequest = "popupReadyForRequest", | ||
ConnectionTypeSelected = "connectionTypeSelected", | ||
RequestWalletLinkUrl = "requestWalletLinkUrl", | ||
PopupUnload = "popupUnload" | ||
export declare enum ConfigEvent { | ||
PopupLoaded = "PopupLoaded", | ||
PopupUnload = "PopupUnload", | ||
SelectSignerType = "selectSignerType", | ||
WalletLinkUpdate = "WalletLinkUpdate" | ||
} | ||
export type SignerType = 'scw' | 'walletlink' | 'extension'; | ||
export declare function isConfigMessage(msg: Message): msg is ConfigMessage; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.isConfigMessage = exports.HostConfigEventType = exports.ClientConfigEventType = void 0; | ||
var ClientConfigEventType; | ||
(function (ClientConfigEventType) { | ||
ClientConfigEventType["SelectConnectionType"] = "selectConnectionType"; | ||
ClientConfigEventType["DappOriginMessage"] = "dappOriginMessage"; | ||
ClientConfigEventType["WalletLinkUrl"] = "walletLinkUrl"; | ||
ClientConfigEventType["WalletLinkQrScanned"] = "walletLinkQrScanned"; | ||
})(ClientConfigEventType || (exports.ClientConfigEventType = ClientConfigEventType = {})); | ||
var HostConfigEventType; | ||
(function (HostConfigEventType) { | ||
HostConfigEventType["PopupListenerAdded"] = "popupListenerAdded"; | ||
HostConfigEventType["PopupReadyForRequest"] = "popupReadyForRequest"; | ||
HostConfigEventType["ConnectionTypeSelected"] = "connectionTypeSelected"; | ||
HostConfigEventType["RequestWalletLinkUrl"] = "requestWalletLinkUrl"; | ||
HostConfigEventType["PopupUnload"] = "popupUnload"; | ||
})(HostConfigEventType || (exports.HostConfigEventType = HostConfigEventType = {})); | ||
function isConfigMessage(msg) { | ||
return msg.type === 'config' && 'event' in msg; | ||
exports.ConfigEvent = exports.isConfigUpdateMessage = void 0; | ||
function isConfigUpdateMessage(message) { | ||
return message.event !== undefined; | ||
} | ||
exports.isConfigMessage = isConfigMessage; | ||
exports.isConfigUpdateMessage = isConfigUpdateMessage; | ||
var ConfigEvent; | ||
(function (ConfigEvent) { | ||
ConfigEvent["PopupLoaded"] = "PopupLoaded"; | ||
ConfigEvent["PopupUnload"] = "PopupUnload"; | ||
ConfigEvent["SelectSignerType"] = "selectSignerType"; | ||
ConfigEvent["WalletLinkUpdate"] = "WalletLinkUpdate"; | ||
})(ConfigEvent || (exports.ConfigEvent = ConfigEvent = {})); |
/// <reference types="node" /> | ||
import { UUID } from 'crypto'; | ||
export type MessageID = UUID; | ||
export interface Message { | ||
type: 'config' | 'scw'; | ||
id: UUID; | ||
version: string; | ||
id: MessageID; | ||
requestId?: MessageID; | ||
} | ||
export type MessageWithOptionalId<T extends Message> = Omit<T, 'id'> & Partial<Pick<T, 'id'>>; | ||
export declare function createMessage<T extends Message>(params: MessageWithOptionalId<T>): T; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.createMessage = void 0; | ||
function createMessage(params) { | ||
var _a; | ||
return Object.assign(Object.assign({}, params), { id: (_a = params.id) !== null && _a !== void 0 ? _a : crypto.randomUUID() }); | ||
} | ||
exports.createMessage = createMessage; |
@@ -1,4 +0,2 @@ | ||
/// <reference types="node" /> | ||
import { UUID } from 'crypto'; | ||
import { Message } from '.'; | ||
import { Message, MessageID } from '.'; | ||
import { RequestAccountsAction } from './Action'; | ||
@@ -8,4 +6,2 @@ import { EncryptedData } from './Cipher'; | ||
interface RPCMessage extends Message { | ||
type: 'scw'; | ||
id: UUID; | ||
sender: string; | ||
@@ -23,3 +19,3 @@ content: unknown; | ||
export interface RPCResponseMessage extends RPCMessage { | ||
requestId: UUID; | ||
requestId: MessageID; | ||
content: { | ||
@@ -26,0 +22,0 @@ encrypted: EncryptedData; |
"use strict"; | ||
// Copyright (c) 2018-2024 Coinbase, Inc. <https://www.coinbase.com/> | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
@@ -4,0 +3,0 @@ exports.ProviderType = exports.RegExpString = exports.IntNumber = exports.BigIntString = exports.AddressString = exports.HexString = exports.OpaqueType = void 0; |
@@ -27,12 +27,18 @@ import { EventEmitter } from 'eventemitter3'; | ||
} | ||
export interface ConstructorOptions { | ||
export interface AppMetadata { | ||
/** Application name */ | ||
appName: string; | ||
/** Application logo image URL; favicon is used if unspecified */ | ||
appLogoUrl?: string | null; | ||
appLogoUrl: string | null; | ||
/** Array of chainIds your dapp supports */ | ||
appChainIds: number[]; | ||
/** Pre-select the wallet connection method */ | ||
smartWalletOnly: boolean; | ||
} | ||
export interface Preference { | ||
options: 'all' | 'smartWalletOnly' | 'eoaOnly'; | ||
keysUrl?: string; | ||
} | ||
export interface ConstructorOptions { | ||
metadata: AppMetadata; | ||
preference: Preference; | ||
} | ||
export {}; |
@@ -1,15 +0,1 @@ | ||
import { CoinbaseWalletProvider } from './CoinbaseWalletProvider'; | ||
import { CoinbaseWalletSDK } from './CoinbaseWalletSDK'; | ||
import { ProviderInterface } from './core/type/ProviderInterface'; | ||
import { Signer } from './sign/SignerInterface'; | ||
export { CoinbaseWalletSDK } from './CoinbaseWalletSDK'; | ||
export default CoinbaseWalletSDK; | ||
declare global { | ||
interface Window { | ||
CoinbaseWalletSDK: typeof CoinbaseWalletSDK; | ||
CoinbaseWalletProvider: typeof CoinbaseWalletProvider; | ||
ethereum?: ProviderInterface; | ||
coinbaseWalletExtension?: ProviderInterface; | ||
coinbaseWalletExtensionSigner?: Signer; | ||
} | ||
} |
@@ -5,10 +5,3 @@ "use strict"; | ||
exports.CoinbaseWalletSDK = void 0; | ||
const CoinbaseWalletProvider_1 = require("./CoinbaseWalletProvider"); | ||
const CoinbaseWalletSDK_1 = require("./CoinbaseWalletSDK"); | ||
var CoinbaseWalletSDK_2 = require("./CoinbaseWalletSDK"); | ||
Object.defineProperty(exports, "CoinbaseWalletSDK", { enumerable: true, get: function () { return CoinbaseWalletSDK_2.CoinbaseWalletSDK; } }); | ||
exports.default = CoinbaseWalletSDK_1.CoinbaseWalletSDK; | ||
if (typeof window !== 'undefined') { | ||
window.CoinbaseWalletSDK = CoinbaseWalletSDK_1.CoinbaseWalletSDK; | ||
window.CoinbaseWalletProvider = CoinbaseWalletProvider_1.CoinbaseWalletProvider; | ||
} | ||
var CoinbaseWalletSDK_1 = require("./CoinbaseWalletSDK"); | ||
Object.defineProperty(exports, "CoinbaseWalletSDK", { enumerable: true, get: function () { return CoinbaseWalletSDK_1.CoinbaseWalletSDK; } }); |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.RPCFetchRequestHandler = void 0; | ||
const version_1 = require("../version"); | ||
const error_1 = require("../core/error"); | ||
@@ -17,3 +18,3 @@ class RPCFetchRequestHandler { | ||
mode: 'cors', | ||
headers: { 'Content-Type': 'application/json' }, | ||
headers: { 'Content-Type': 'application/json', 'X-Cbw-Sdk-Version': version_1.LIB_VERSION }, | ||
}); | ||
@@ -20,0 +21,0 @@ const response = await res.json(); |
@@ -1,18 +0,14 @@ | ||
import { Signer, SignerUpdateListener } from '../SignerInterface'; | ||
import { PopUpCommunicator } from './transport/PopUpCommunicator'; | ||
import { Signer, StateUpdateListener } from '../interface'; | ||
import { PopUpCommunicator } from '../../core/communicator/PopUpCommunicator'; | ||
import { AddressString } from '../../core/type'; | ||
import { RequestArguments } from '../../core/type/ProviderInterface'; | ||
import { AppMetadata, RequestArguments } from '../../core/type/ProviderInterface'; | ||
export declare class SCWSigner implements Signer { | ||
private appName; | ||
private appLogoUrl; | ||
private appChainIds; | ||
private puc; | ||
private metadata; | ||
private popupCommunicator; | ||
private keyManager; | ||
private stateManager; | ||
constructor(options: { | ||
appName: string; | ||
appLogoUrl: string | null; | ||
appChainIds: number[]; | ||
puc: PopUpCommunicator; | ||
updateListener: SignerUpdateListener; | ||
metadata: AppMetadata; | ||
popupCommunicator: PopUpCommunicator; | ||
updateListener: StateUpdateListener; | ||
}); | ||
@@ -23,3 +19,2 @@ handshake(): Promise<AddressString[]>; | ||
private tryLocalHandling; | ||
private tryBackendHandling; | ||
private sendEncryptedRequest; | ||
@@ -26,0 +21,0 @@ private createRequestMessage; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.SCWSigner = void 0; | ||
const version_1 = require("../../version"); | ||
const SCWKeyManager_1 = require("./SCWKeyManager"); | ||
const SCWStateManager_1 = require("./SCWStateManager"); | ||
const constants_1 = require("../../core/constants"); | ||
const error_1 = require("../../core/error"); | ||
const message_1 = require("../../core/message"); | ||
const Action_1 = require("../../core/message/Action"); | ||
@@ -14,13 +13,8 @@ const Cipher_1 = require("../../core/message/Cipher"); | ||
constructor(options) { | ||
this.appName = options.appName; | ||
this.appLogoUrl = options.appLogoUrl; | ||
this.appChainIds = options.appChainIds; | ||
this.puc = options.puc; | ||
this.metadata = options.metadata; | ||
this.popupCommunicator = options.popupCommunicator; | ||
this.keyManager = new SCWKeyManager_1.SCWKeyManager(); | ||
this.stateManager = new SCWStateManager_1.SCWStateManager({ | ||
appChainIds: this.appChainIds, | ||
updateListener: { | ||
onAccountsUpdate: (...args) => options.updateListener.onAccountsUpdate(this, ...args), | ||
onChainUpdate: (...args) => options.updateListener.onChainUpdate(this, ...args), | ||
}, | ||
appChainIds: this.metadata.appChainIds, | ||
updateListener: options.updateListener, | ||
}); | ||
@@ -33,16 +27,10 @@ this.handshake = this.handshake.bind(this); | ||
async handshake() { | ||
if (!this.puc.connected) { | ||
await this.puc.connect(); | ||
} | ||
await this.popupCommunicator.connect(); | ||
const handshakeMessage = await this.createRequestMessage({ | ||
handshake: { | ||
method: Action_1.SupportedEthereumMethods.EthRequestAccounts, | ||
params: { | ||
dappName: this.appName, | ||
dappLogoUrl: this.appLogoUrl, | ||
chainIds: this.appChainIds, | ||
}, | ||
params: this.metadata, | ||
}, | ||
}); | ||
const response = (await this.puc.request(handshakeMessage)); | ||
const response = (await this.popupCommunicator.postMessageForResponse(handshakeMessage)); | ||
// store peer's public key | ||
@@ -67,6 +55,3 @@ if ('failure' in response.content) | ||
} | ||
const backendResult = await this.tryBackendHandling(request); | ||
if (backendResult !== undefined) { | ||
return backendResult; | ||
} | ||
await this.popupCommunicator.connect(); | ||
const response = await this.sendEncryptedRequest(request); | ||
@@ -110,23 +95,3 @@ const decrypted = await this.decryptResponseMessage(response); | ||
} | ||
async tryBackendHandling(request) { | ||
switch (request.method) { | ||
case Action_1.SupportedEthereumMethods.WalletGetCallsStatus: { | ||
const requestBody = Object.assign(Object.assign({}, request), { jsonrpc: '2.0', id: crypto.randomUUID() }); | ||
const res = await window.fetch(constants_1.CB_KEYS_BACKEND_URL, { | ||
method: 'POST', | ||
body: JSON.stringify(requestBody), | ||
mode: 'cors', | ||
headers: { 'Content-Type': 'application/json', 'X-Cbw-Sdk-Version': version_1.LIB_VERSION }, | ||
}); | ||
const response = await res.json(); | ||
return response.result; | ||
} | ||
default: | ||
return undefined; | ||
} | ||
} | ||
async sendEncryptedRequest(request) { | ||
if (!this.puc.connected) { | ||
await this.puc.connect(); | ||
} | ||
const sharedSecret = await this.keyManager.getSharedSecret(); | ||
@@ -141,3 +106,3 @@ if (!sharedSecret) { | ||
const message = await this.createRequestMessage({ encrypted }); | ||
const response = (await this.puc.request(message)); | ||
const response = (await this.popupCommunicator.postMessageForResponse(message)); | ||
return response; | ||
@@ -147,10 +112,7 @@ } | ||
const publicKey = await (0, Cipher_1.exportKeyToHexString)('public', await this.keyManager.getOwnPublicKey()); | ||
return { | ||
type: 'scw', | ||
id: crypto.randomUUID(), | ||
return (0, message_1.createMessage)({ | ||
sender: publicKey, | ||
content, | ||
version: version_1.LIB_VERSION, | ||
timestamp: new Date(), | ||
}; | ||
}); | ||
} | ||
@@ -157,0 +119,0 @@ async decryptResponseMessage(message) { |
@@ -1,2 +0,2 @@ | ||
import { StateUpdateListener } from '../UpdateListenerInterface'; | ||
import { StateUpdateListener } from '../interface'; | ||
import { AddressString, Chain } from '../../core/type'; | ||
@@ -3,0 +3,0 @@ export declare class SCWStateManager { |
@@ -1,34 +0,20 @@ | ||
import { PopUpCommunicator } from './scw/transport/PopUpCommunicator'; | ||
import { Signer } from './SignerInterface'; | ||
import { SignRequestHandlerListener } from './UpdateListenerInterface'; | ||
interface SignerConfiguratorOptions { | ||
appName: string; | ||
appLogoUrl?: string | null; | ||
appChainIds: number[]; | ||
smartWalletOnly: boolean; | ||
import { Signer, SignRequestHandlerListener } from './interface'; | ||
import { SignerType } from '../core/message/ConfigMessage'; | ||
import { ConstructorOptions } from '../core/type/ProviderInterface'; | ||
type SignerConfiguratorOptions = ConstructorOptions & { | ||
updateListener: SignRequestHandlerListener; | ||
popupCommunicator: PopUpCommunicator; | ||
} | ||
}; | ||
export declare class SignerConfigurator { | ||
private appName; | ||
private appLogoUrl; | ||
private appChainIds; | ||
private smartWalletOnly; | ||
private metadata; | ||
private preference; | ||
private popupCommunicator; | ||
private updateListener; | ||
private signerTypeStorage; | ||
private signerTypeSelectionResolver; | ||
signerType: string | null; | ||
signer: Signer | undefined; | ||
constructor(options: Readonly<SignerConfiguratorOptions>); | ||
private readonly updateRelay; | ||
initSigner: () => void; | ||
private initScwSigner; | ||
private initWalletLinkSigner; | ||
private initExtensionSigner; | ||
onDisconnect(): Promise<void>; | ||
getWalletLinkQRCodeUrl(): string; | ||
completeSignerTypeSelection(): Promise<unknown>; | ||
private setSignerType; | ||
tryRestoringSignerFromPersistedType(): Signer | undefined; | ||
selectSigner(): Promise<Signer>; | ||
clearStorage(): void; | ||
private selectSignerType; | ||
protected initSignerFromType(signerType: SignerType): Signer; | ||
} | ||
export {}; |
"use strict"; | ||
var __rest = (this && this.__rest) || function (s, e) { | ||
var t = {}; | ||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) | ||
t[p] = s[p]; | ||
if (s != null && typeof Object.getOwnPropertySymbols === "function") | ||
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { | ||
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) | ||
t[p[i]] = s[p[i]]; | ||
} | ||
return t; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
@@ -6,3 +17,7 @@ exports.SignerConfigurator = void 0; | ||
const WLSigner_1 = require("./walletlink/WLSigner"); | ||
const PopUpCommunicator_1 = require("../core/communicator/PopUpCommunicator"); | ||
const constants_1 = require("../core/constants"); | ||
const error_1 = require("../core/error"); | ||
const message_1 = require("../core/message"); | ||
const ConfigMessage_1 = require("../core/message/ConfigMessage"); | ||
const ScopedLocalStorage_1 = require("../core/storage/ScopedLocalStorage"); | ||
@@ -12,127 +27,54 @@ const SIGNER_TYPE_KEY = 'SignerType'; | ||
constructor(options) { | ||
var _a; | ||
this.signerTypeStorage = new ScopedLocalStorage_1.ScopedLocalStorage('CBWSDK', 'SignerConfigurator'); | ||
this.updateRelay = { | ||
onAccountsUpdate: (signer, ...rest) => { | ||
if (this.signer && signer !== this.signer) | ||
return; // ignore events from inactive signers | ||
this.updateListener.onAccountsUpdate(...rest); | ||
}, | ||
onChainUpdate: (signer, ...rest) => { | ||
var _a; | ||
if (this.signer && signer !== this.signer) | ||
return; // ignore events from inactive signers | ||
if (signer instanceof WLSigner_1.WLSigner) { | ||
(_a = this.signerTypeSelectionResolver) === null || _a === void 0 ? void 0 : _a.call(this, 'walletlink'); | ||
} | ||
this.updateListener.onChainUpdate(...rest); | ||
}, | ||
}; | ||
this.initSigner = () => { | ||
switch (this.signerType) { | ||
case 'scw': | ||
this.initScwSigner(); | ||
break; | ||
case 'walletlink': | ||
this.initWalletLinkSigner(); | ||
break; | ||
case 'extension': | ||
this.initExtensionSigner(); | ||
break; | ||
} | ||
}; | ||
this.popupCommunicator = options.popupCommunicator; | ||
const _a = options.preference, { keysUrl } = _a, preferenceWithoutKeysUrl = __rest(_a, ["keysUrl"]); | ||
this.preference = preferenceWithoutKeysUrl; | ||
this.popupCommunicator = new PopUpCommunicator_1.PopUpCommunicator({ | ||
url: keysUrl !== null && keysUrl !== void 0 ? keysUrl : constants_1.CB_KEYS_URL, | ||
}); | ||
this.updateListener = options.updateListener; | ||
this.appName = options.appName; | ||
this.appLogoUrl = (_a = options.appLogoUrl) !== null && _a !== void 0 ? _a : null; | ||
this.appChainIds = options.appChainIds; | ||
this.smartWalletOnly = options.smartWalletOnly; | ||
this.metadata = options.metadata; | ||
} | ||
tryRestoringSignerFromPersistedType() { | ||
const persistedSignerType = this.signerTypeStorage.getItem(SIGNER_TYPE_KEY); | ||
this.signerType = persistedSignerType; | ||
try { | ||
if (persistedSignerType) { | ||
this.initSigner(); | ||
} | ||
if (persistedSignerType) { | ||
return this.initSignerFromType(persistedSignerType); | ||
} | ||
catch (_b) { | ||
this.onDisconnect(); | ||
} | ||
// getWalletLinkQRCodeUrl is called by the PopUpCommunicator when | ||
// it receives message.type === 'wlQRCodeUrl' from the cb-wallet-scw popup | ||
// its injected because we don't want to instantiate WalletLinkSigner until we have to | ||
this.getWalletLinkQRCodeUrl = this.getWalletLinkQRCodeUrl.bind(this); | ||
this.popupCommunicator.setGetWalletLinkQRCodeUrlCallback(this.getWalletLinkQRCodeUrl); | ||
this.setSignerType = this.setSignerType.bind(this); | ||
this.initWalletLinkSigner = this.initWalletLinkSigner.bind(this); | ||
return undefined; | ||
} | ||
initScwSigner() { | ||
if (this.signer instanceof SCWSigner_1.SCWSigner) | ||
return; | ||
this.signer = new SCWSigner_1.SCWSigner({ | ||
appName: this.appName, | ||
appLogoUrl: this.appLogoUrl, | ||
appChainIds: this.appChainIds, | ||
puc: this.popupCommunicator, | ||
updateListener: this.updateRelay, | ||
}); | ||
async selectSigner() { | ||
const signerType = await this.selectSignerType(); | ||
const signer = this.initSignerFromType(signerType); | ||
return signer; | ||
} | ||
initWalletLinkSigner() { | ||
if (this.signer instanceof WLSigner_1.WLSigner) | ||
return; | ||
this.signer = new WLSigner_1.WLSigner({ | ||
appName: this.appName, | ||
appLogoUrl: this.appLogoUrl, | ||
updateListener: this.updateRelay, | ||
}); | ||
} | ||
initExtensionSigner() { | ||
const extensionSigner = window.coinbaseWalletExtensionSigner; | ||
if (!extensionSigner) { | ||
throw error_1.standardErrors.provider.unauthorized('Coinbase Wallet extension signer not found'); | ||
} | ||
this.signer = extensionSigner; | ||
} | ||
async onDisconnect() { | ||
var _a; | ||
this.signerType = null; | ||
clearStorage() { | ||
this.signerTypeStorage.removeItem(SIGNER_TYPE_KEY); | ||
await ((_a = this.signer) === null || _a === void 0 ? void 0 : _a.disconnect()); | ||
this.signer = undefined; | ||
} | ||
getWalletLinkQRCodeUrl() { | ||
this.initWalletLinkSigner(); | ||
if (!(this.signer instanceof WLSigner_1.WLSigner)) { | ||
throw error_1.standardErrors.rpc.internal('Signer not initialized or Signer.getWalletLinkUrl not defined'); | ||
} | ||
return this.signer.getQRCodeUrl(); | ||
} | ||
async completeSignerTypeSelection() { | ||
async selectSignerType() { | ||
await this.popupCommunicator.connect(); | ||
return new Promise((resolve, reject) => { | ||
this.signerTypeSelectionResolver = (signerType) => { | ||
this.setSignerType(signerType); | ||
resolve(signerType); | ||
}; | ||
this.popupCommunicator | ||
.selectSignerType({ | ||
smartWalletOnly: this.smartWalletOnly, | ||
isExtensionSignerAvailable: Boolean(window.coinbaseWalletExtensionSigner), | ||
}) | ||
.then((signerType) => { | ||
var _a; | ||
(_a = this.signerTypeSelectionResolver) === null || _a === void 0 ? void 0 : _a.call(this, signerType); | ||
}) | ||
.catch((err) => { | ||
reject(err); | ||
}); | ||
const message = (0, message_1.createMessage)({ | ||
event: ConfigMessage_1.ConfigEvent.SelectSignerType, | ||
data: this.preference, | ||
}); | ||
const response = await this.popupCommunicator.postMessageForResponse(message); | ||
const signerType = response.data; | ||
this.signerTypeStorage.setItem(SIGNER_TYPE_KEY, signerType); | ||
return signerType; | ||
} | ||
// storage methods | ||
setSignerType(signerType) { | ||
if (this.signerType === signerType) | ||
return; | ||
this.signerType = signerType; | ||
this.signerTypeStorage.setItem(SIGNER_TYPE_KEY, this.signerType); | ||
initSignerFromType(signerType) { | ||
const signerClasses = { | ||
scw: SCWSigner_1.SCWSigner, | ||
walletlink: WLSigner_1.WLSigner, | ||
extension: undefined, | ||
}; | ||
const SignerClass = signerClasses[signerType]; | ||
if (!SignerClass) { | ||
throw error_1.standardErrors.rpc.internal(`SignerConfigurator: Unknown signer type ${signerType}`); | ||
} | ||
return new SignerClass({ | ||
metadata: this.metadata, | ||
popupCommunicator: this.popupCommunicator, | ||
updateListener: this.updateListener, | ||
}); | ||
} | ||
} | ||
exports.SignerConfigurator = SignerConfigurator; |
@@ -1,2 +0,2 @@ | ||
import { SignRequestHandlerListener } from './UpdateListenerInterface'; | ||
import { SignRequestHandlerListener } from './interface'; | ||
import { AddressString } from '../core/type'; | ||
@@ -7,6 +7,5 @@ import { ConstructorOptions, RequestArguments } from '../core/type/ProviderInterface'; | ||
updateListener: SignRequestHandlerListener; | ||
keysUrl?: string; | ||
}; | ||
export declare class SignRequestHandler implements RequestHandler { | ||
private popupCommunicator; | ||
private _signer; | ||
private updateListener; | ||
@@ -16,6 +15,8 @@ private signerConfigurator; | ||
handleRequest(request: RequestArguments, accounts: AddressString[]): Promise<unknown>; | ||
private eth_requestAccounts; | ||
private requestAccounts; | ||
canHandleRequest(request: RequestArguments): boolean; | ||
onDisconnect(): Promise<void>; | ||
private tryRestoringSignerFromPersistedType; | ||
private useSigner; | ||
} | ||
export {}; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.SignRequestHandler = void 0; | ||
const PopUpCommunicator_1 = require("./scw/transport/PopUpCommunicator"); | ||
const SignerConfigurator_1 = require("./SignerConfigurator"); | ||
const constants_1 = require("../core/constants"); | ||
const error_1 = require("../core/error"); | ||
class SignRequestHandler { | ||
constructor(options) { | ||
var _a; | ||
this.popupCommunicator = new PopUpCommunicator_1.PopUpCommunicator({ | ||
url: (_a = options.keysUrl) !== null && _a !== void 0 ? _a : constants_1.CB_KEYS_URL, | ||
}); | ||
this.updateListener = options.updateListener; | ||
this.signerConfigurator = new SignerConfigurator_1.SignerConfigurator(Object.assign(Object.assign({}, options), { popupCommunicator: this.popupCommunicator })); | ||
this.signerConfigurator = new SignerConfigurator_1.SignerConfigurator(options); | ||
this.tryRestoringSignerFromPersistedType(); | ||
} | ||
@@ -20,8 +15,11 @@ async handleRequest(request, accounts) { | ||
if (request.method === 'eth_requestAccounts') { | ||
return await this.eth_requestAccounts(accounts); | ||
if (accounts.length > 0) | ||
return accounts; | ||
return await this.requestAccounts(); | ||
} | ||
if (!this.signerConfigurator.signer || accounts.length <= 0) { | ||
const signer = await this.useSigner(); | ||
if (accounts.length <= 0) { | ||
throw error_1.standardErrors.provider.unauthorized("Must call 'eth_requestAccounts' before other methods"); | ||
} | ||
return await this.signerConfigurator.signer.request(request); | ||
return await signer.request(request); | ||
} | ||
@@ -35,34 +33,7 @@ catch (err) { | ||
} | ||
async eth_requestAccounts(accounts) { | ||
var _a; | ||
if (accounts.length > 0) { | ||
this.updateListener.onConnect(); | ||
return Promise.resolve(accounts); | ||
} | ||
if (!this.signerConfigurator.signerType) { | ||
// WL: this promise hangs until the QR code is scanned | ||
// SCW: this promise hangs until the user signs in with passkey | ||
await this.signerConfigurator.completeSignerTypeSelection(); | ||
} | ||
try { | ||
// in the case of walletlink, this doesn't do anything since signer is initialized | ||
// when the wallet link QR code url is requested | ||
this.signerConfigurator.initSigner(); | ||
const ethAddresses = await ((_a = this.signerConfigurator.signer) === null || _a === void 0 ? void 0 : _a.handshake()); | ||
if (Array.isArray(ethAddresses)) { | ||
if (this.signerConfigurator.signerType === 'walletlink') { | ||
this.popupCommunicator.walletLinkQrScanned(); | ||
} | ||
this.updateListener.onConnect(); | ||
return Promise.resolve(ethAddresses); | ||
} | ||
return Promise.reject(error_1.standardErrors.rpc.internal('Failed to get accounts')); | ||
} | ||
catch (err) { | ||
if (this.signerConfigurator.signerType === 'walletlink') { | ||
this.popupCommunicator.disconnect(); | ||
await this.onDisconnect(); | ||
} | ||
throw err; | ||
} | ||
async requestAccounts() { | ||
const signer = await this.useSigner(); | ||
const ethAddresses = await signer.handshake(); | ||
this.updateListener.onConnect(); | ||
return ethAddresses; | ||
} | ||
@@ -88,3 +59,2 @@ canHandleRequest(request) { | ||
'wallet_sendCalls', | ||
'wallet_getCallsStatus', | ||
]; | ||
@@ -94,5 +64,15 @@ return methodsThatRequireSigning.includes(request.method); | ||
async onDisconnect() { | ||
await this.signerConfigurator.onDisconnect(); | ||
this._signer = undefined; | ||
this.signerConfigurator.clearStorage(); | ||
} | ||
tryRestoringSignerFromPersistedType() { | ||
this._signer = this.signerConfigurator.tryRestoringSignerFromPersistedType(); | ||
} | ||
async useSigner() { | ||
if (this._signer) | ||
return this._signer; | ||
this._signer = await this.signerConfigurator.selectSigner(); | ||
return this._signer; | ||
} | ||
} | ||
exports.SignRequestHandler = SignRequestHandler; |
@@ -365,3 +365,5 @@ "use strict"; | ||
async publishEvent(event, unencryptedData, callWebhook = false) { | ||
const data = await this.cipher.encrypt(JSON.stringify(Object.assign(Object.assign({}, unencryptedData), { origin: location.origin, relaySource: window.coinbaseWalletExtension ? 'injected_sdk' : 'sdk' }))); | ||
const data = await this.cipher.encrypt(JSON.stringify(Object.assign(Object.assign({}, unencryptedData), { origin: location.origin, relaySource: 'coinbaseWalletExtension' in window && window.coinbaseWalletExtension | ||
? 'injected_sdk' | ||
: 'sdk' }))); | ||
const message = { | ||
@@ -368,0 +370,0 @@ type: 'PublishEvent', |
@@ -61,3 +61,3 @@ /// <reference types="node" /> | ||
scanQRCode(regExp: RegExpString): CancelablePromise<Web3Response<"scanQRCode">>; | ||
getQRCodeUrl(): string; | ||
getWalletLinkSession(): WalletLinkSession; | ||
genericRequest(data: object, action: string): CancelablePromise<Web3Response<"generic">>; | ||
@@ -64,0 +64,0 @@ sendGenericMessage(request: Web3Request<'generic'>): CancelablePromise<Web3Response<'generic'>>; |
@@ -5,3 +5,2 @@ "use strict"; | ||
exports.WalletLinkRelay = void 0; | ||
const version_1 = require("../../../version"); | ||
const WalletLinkConnection_1 = require("./connection/WalletLinkConnection"); | ||
@@ -256,4 +255,4 @@ const DiagnosticLogger_1 = require("./DiagnosticLogger"); | ||
} | ||
getQRCodeUrl() { | ||
return (0, util_1.createQrUrl)(this._session.id, this._session.secret, this.linkAPIUrl, false, version_1.LIB_VERSION, this.dappDefaultChain); | ||
getWalletLinkSession() { | ||
return this._session; | ||
} | ||
@@ -260,0 +259,0 @@ genericRequest(data, action) { |
@@ -1,2 +0,2 @@ | ||
import { StateUpdateListener } from '../../UpdateListenerInterface'; | ||
import { StateUpdateListener } from '../../interface'; | ||
import { AddressString } from '../../../core/type'; | ||
@@ -21,3 +21,3 @@ import { RequestArguments } from '../../../core/type/ProviderInterface'; | ||
}); | ||
getQRCodeUrl(): string; | ||
getWalletLinkSession(): import("./type/WalletLinkSession").WalletLinkSession; | ||
get selectedAddress(): AddressString | undefined; | ||
@@ -24,0 +24,0 @@ private get jsonRpcUrl(); |
@@ -54,5 +54,5 @@ "use strict"; | ||
} | ||
getQRCodeUrl() { | ||
getWalletLinkSession() { | ||
const relay = this.initializeRelay(); | ||
return relay.getQRCodeUrl(); | ||
return relay.getWalletLinkSession(); | ||
} | ||
@@ -59,0 +59,0 @@ get selectedAddress() { |
@@ -1,15 +0,19 @@ | ||
import { Signer, SignerUpdateListener } from '../SignerInterface'; | ||
import { Signer, StateUpdateListener } from '../interface'; | ||
import { PopUpCommunicator } from '../../core/communicator/PopUpCommunicator'; | ||
import { AddressString } from '../../core/type'; | ||
import { RequestArguments } from '../../core/type/ProviderInterface'; | ||
import { AppMetadata, RequestArguments } from '../../core/type/ProviderInterface'; | ||
export declare class WLSigner implements Signer { | ||
private popupCommunicator; | ||
private adapter; | ||
constructor(options: { | ||
appName: string; | ||
appLogoUrl: string | null; | ||
updateListener: SignerUpdateListener; | ||
metadata: AppMetadata; | ||
popupCommunicator: PopUpCommunicator; | ||
updateListener: StateUpdateListener; | ||
}); | ||
handshake(): Promise<AddressString[]>; | ||
request<T>(requestArgs: RequestArguments): Promise<T>; | ||
getQRCodeUrl(): string; | ||
private postWalletLinkSession; | ||
private postWalletLinkConnected; | ||
private postWalletLinkUpdate; | ||
disconnect(): Promise<void>; | ||
} |
@@ -6,11 +6,19 @@ "use strict"; | ||
const constants_1 = require("../../core/constants"); | ||
const ConfigMessage_1 = require("../../core/message/ConfigMessage"); | ||
class WLSigner { | ||
constructor(options) { | ||
this.adapter = new WLRelayAdapter_1.WLRelayAdapter(Object.assign(Object.assign({}, options), { walletlinkUrl: constants_1.WALLETLINK_URL, updateListener: { | ||
onAccountsUpdate: (...args) => options.updateListener.onAccountsUpdate(this, ...args), | ||
onChainUpdate: (...args) => options.updateListener.onChainUpdate(this, ...args), | ||
} })); | ||
const { appName, appLogoUrl } = options.metadata; | ||
this.popupCommunicator = options.popupCommunicator; | ||
this.adapter = new WLRelayAdapter_1.WLRelayAdapter({ | ||
appName, | ||
appLogoUrl, | ||
walletlinkUrl: constants_1.WALLETLINK_URL, | ||
updateListener: options.updateListener, | ||
}); | ||
this.postWalletLinkSession(); | ||
} | ||
async handshake() { | ||
return await this.request({ method: 'eth_requestAccounts' }); | ||
const ethAddresses = await this.request({ method: 'eth_requestAccounts' }); | ||
this.postWalletLinkConnected(); | ||
return ethAddresses; | ||
} | ||
@@ -20,5 +28,15 @@ async request(requestArgs) { | ||
} | ||
getQRCodeUrl() { | ||
return this.adapter.getQRCodeUrl(); | ||
postWalletLinkSession() { | ||
const { id, secret } = this.adapter.getWalletLinkSession(); | ||
this.postWalletLinkUpdate({ session: { id, secret } }); | ||
} | ||
postWalletLinkConnected() { | ||
this.postWalletLinkUpdate({ connected: true }); | ||
} | ||
postWalletLinkUpdate(data) { | ||
this.popupCommunicator.postMessage({ | ||
event: ConfigMessage_1.ConfigEvent.WalletLinkUpdate, | ||
data, | ||
}); | ||
} | ||
async disconnect() { | ||
@@ -25,0 +43,0 @@ await this.adapter.close(); |
@@ -1,1 +0,1 @@ | ||
export declare const LIB_VERSION = "4.0.0-beta.7"; | ||
export declare const LIB_VERSION = "4.0.0-beta.8"; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.LIB_VERSION = void 0; | ||
exports.LIB_VERSION = '4.0.0-beta.7'; | ||
exports.LIB_VERSION = '4.0.0-beta.8'; |
@@ -27,3 +27,3 @@ # Using Coinbase Wallet SDK v4 beta with wagmi | ||
- Only to `baseSepolia` and `base` are supported by the scw frontend popup at this time. We'll need to replace `mainnet` and `sepolia` with supported chains. | ||
- Only to `baseSepolia` is supported by http://keys.coinbase.com at this time. | ||
- Remove unecessary connectors | ||
@@ -35,10 +35,9 @@ - Edit `src/wagmi.ts` to look like this: | ||
import { http, createConfig } from 'wagmi'; | ||
import { base, baseSepolia } from 'wagmi/chains'; | ||
import { baseSepolia } from 'wagmi/chains'; | ||
import { coinbaseWallet } from 'wagmi/connectors'; | ||
export const config = createConfig({ | ||
chains: [baseSepolia, base], | ||
connectors: [coinbaseWallet({ appName: 'Create Wagmi', chainIds: [baseSepolia.id, base.id] })], | ||
chains: [baseSepolia], | ||
connectors: [coinbaseWallet({ appName: 'Create Wagmi', chainIds: [baseSepolia.id] })], | ||
transports: { | ||
[base.id]: http(), | ||
[baseSepolia.id]: http(), | ||
@@ -45,0 +44,0 @@ }, |
{ | ||
"name": "@coinbase/wallet-sdk", | ||
"version": "4.0.0-beta.7", | ||
"version": "4.0.0-beta.8", | ||
"description": "Coinbase Wallet JavaScript SDK", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
298364
147
6956