@coinbase/wallet-sdk
Advanced tools
Comparing version 4.0.0-rc.1 to 4.0.0-rc.2
@@ -9,7 +9,8 @@ "use strict"; | ||
const error_1 = require("./core/error"); | ||
const util_1 = require("./core/provider/util"); | ||
const util_2 = require("./core/util"); | ||
const type_1 = require("./core/type"); | ||
const util_1 = require("./core/type/util"); | ||
const SignHandler_1 = require("./sign/SignHandler"); | ||
const FilterPolyfill_1 = require("./vendor-js/filter/FilterPolyfill"); | ||
const provider_1 = require("./util/provider"); | ||
const method_1 = require("./core/provider/method"); | ||
const FilterPolyfill_1 = require("./util/FilterPolyfill"); | ||
class CoinbaseWalletProvider extends eventemitter3_1.default { | ||
@@ -23,9 +24,7 @@ constructor(params) { | ||
handshake: async (_) => { | ||
if (this.connected) { | ||
this.emit('connect', { chainId: (0, util_2.prepend0x)(this.chain.id.toString(16)) }); | ||
return this.accounts; | ||
} | ||
try { | ||
const accounts = await this.signHandler.handshake(); | ||
this.emit('connect', { chainId: (0, util_2.prepend0x)(this.chain.id.toString(16)) }); | ||
const accounts = this.connected // already connected | ||
? this.accounts | ||
: await this.signHandler.handshake(); | ||
this.emit('connect', { chainId: (0, util_1.hexStringFromIntNumber)((0, type_1.IntNumber)(this.chain.id)) }); | ||
return accounts; | ||
@@ -50,3 +49,3 @@ } | ||
}, | ||
fetch: (request) => (0, util_1.fetchRPCRequest)(request, this.chain), | ||
fetch: (request) => (0, provider_1.fetchRPCRequest)(request, this.chain), | ||
state: (request) => { | ||
@@ -81,3 +80,3 @@ const getConnectedAccounts = () => { | ||
onAccountsUpdate: ({ accounts, source }) => { | ||
if ((0, util_2.areAddressArraysEqual)(this.accounts, accounts)) | ||
if ((0, util_1.areAddressArraysEqual)(this.accounts, accounts)) | ||
return; | ||
@@ -95,3 +94,3 @@ this.accounts = accounts; | ||
return; | ||
this.emit('chainChanged', (0, util_2.prepend0x)(chain.id.toString(16))); | ||
this.emit('chainChanged', (0, util_1.hexStringFromIntNumber)((0, type_1.IntNumber)(chain.id))); | ||
}, | ||
@@ -110,3 +109,3 @@ }; | ||
var _a; | ||
const invalidArgsError = (0, util_1.checkErrorForInvalidRequestArgs)(args); | ||
const invalidArgsError = (0, provider_1.checkErrorForInvalidRequestArgs)(args); | ||
if (invalidArgsError) | ||
@@ -125,3 +124,3 @@ throw invalidArgsError; | ||
async enable() { | ||
(0, util_2.showDeprecationWarning)('enable', 'use request({ method: "eth_requestAccounts" })'); | ||
console.warn(`.enable() has been deprecated. Please use .request({ method: "eth_requestAccounts" }) instead.`); | ||
return await this.request({ | ||
@@ -128,0 +127,0 @@ method: 'eth_requestAccounts', |
@@ -7,28 +7,19 @@ "use strict"; | ||
const CoinbaseWalletProvider_1 = require("./CoinbaseWalletProvider"); | ||
const ScopedLocalStorage_1 = require("./core/storage/ScopedLocalStorage"); | ||
const ScopedLocalStorage_1 = require("./util/ScopedLocalStorage"); | ||
const version_1 = require("./version"); | ||
const util_1 = require("./core/provider/util"); | ||
const util_2 = require("./core/util"); | ||
const util_1 = require("./core/type/util"); | ||
const provider_1 = require("./util/provider"); | ||
class CoinbaseWalletSDK { | ||
constructor(metadata) { | ||
this.metadata = metadata; | ||
this.metadata = { | ||
appName: metadata.appName || 'Dapp', | ||
appLogoUrl: metadata.appLogoUrl || (0, util_1.getFavicon)(), | ||
appChainIds: metadata.appChainIds || [], | ||
}; | ||
this.storeLatestVersion(); | ||
} | ||
makeWeb3Provider(preference = { options: 'all' }) { | ||
var _a, _b; | ||
const { appName = 'Dapp', appLogoUrl = (0, util_2.getFavicon)(), appChainIds = [] } = this.metadata; | ||
const provider = (0, util_1.getCoinbaseInjectedProvider)(preference); | ||
if (provider) { | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
(_b = (_a = provider).setAppInfo) === null || _b === void 0 ? void 0 : _b.call(_a, appName, appLogoUrl, appChainIds); | ||
return provider; | ||
} | ||
return new CoinbaseWalletProvider_1.CoinbaseWalletProvider({ | ||
metadata: { | ||
appName, | ||
appLogoUrl, | ||
appChainIds, | ||
}, | ||
preference, | ||
}); | ||
var _a; | ||
const params = { metadata: this.metadata, preference }; | ||
return (_a = (0, provider_1.getCoinbaseInjectedProvider)(params)) !== null && _a !== void 0 ? _a : new CoinbaseWalletProvider_1.CoinbaseWalletProvider(params); | ||
} | ||
@@ -35,0 +26,0 @@ /** |
import { CrossDomainCommunicator } from '../communicator/CrossDomainCommunicator'; | ||
import { Message } from '../message'; | ||
import { ConfigUpdateMessage } from '../message/ConfigMessage'; | ||
import { ConfigUpdateMessage, Message } from '../message'; | ||
export declare class PopUpCommunicator extends CrossDomainCommunicator { | ||
@@ -5,0 +4,0 @@ private resolveConnection?; |
@@ -7,3 +7,3 @@ "use strict"; | ||
const error_1 = require("../error"); | ||
const ConfigMessage_1 = require("../message/ConfigMessage"); | ||
const message_1 = require("../message"); | ||
const POPUP_WIDTH = 420; | ||
@@ -25,3 +25,3 @@ const POPUP_HEIGHT = 540; | ||
const message = event.data; | ||
if ((0, ConfigMessage_1.isConfigUpdateMessage)(message)) { | ||
if ((0, message_1.isConfigUpdateMessage)(message)) { | ||
this.handleIncomingConfigUpdate(message); | ||
@@ -36,3 +36,3 @@ } | ||
switch (message.event) { | ||
case ConfigMessage_1.ConfigEvent.PopupLoaded: | ||
case message_1.ConfigEvent.PopupLoaded: | ||
// Handshake Step 2: After receiving PopupHello from popup, Dapp sends DappHello | ||
@@ -47,3 +47,3 @@ // to FE to help FE confirm the origin of the Dapp, as well as SDK version. | ||
break; | ||
case ConfigMessage_1.ConfigEvent.PopupUnload: | ||
case message_1.ConfigEvent.PopupUnload: | ||
this.disconnect(); | ||
@@ -50,0 +50,0 @@ break; |
@@ -1,2 +0,2 @@ | ||
import { Message, MessageID } from '.'; | ||
import { Message, MessageID } from './Message'; | ||
export interface ConfigUpdateMessage extends Message { | ||
@@ -3,0 +3,0 @@ event: ConfigEvent; |
@@ -1,9 +0,5 @@ | ||
/// <reference types="node" /> | ||
import { UUID } from 'crypto'; | ||
export type MessageID = UUID; | ||
export interface Message { | ||
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; | ||
export * from './ConfigMessage'; | ||
export * from './Message'; | ||
export * from './RPCMessage'; | ||
export * from './RPCRequest'; | ||
export * from './RPCResponse'; |
"use strict"; | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
var desc = Object.getOwnPropertyDescriptor(m, k); | ||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { | ||
desc = { enumerable: true, get: function() { return m[k]; } }; | ||
} | ||
Object.defineProperty(o, k2, desc); | ||
}) : (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
o[k2] = m[k]; | ||
})); | ||
var __exportStar = (this && this.__exportStar) || function(m, exports) { | ||
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); | ||
}; | ||
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; | ||
__exportStar(require("./ConfigMessage"), exports); | ||
__exportStar(require("./Message"), exports); | ||
__exportStar(require("./RPCMessage"), exports); | ||
__exportStar(require("./RPCRequest"), exports); | ||
__exportStar(require("./RPCResponse"), exports); |
@@ -1,5 +0,4 @@ | ||
import { Message, MessageID } from '.'; | ||
import { RequestAccountsAction } from './Action'; | ||
import { EncryptedData } from './Cipher'; | ||
import { Message, MessageID } from './Message'; | ||
import { SerializedEthereumRpcError } from '../error'; | ||
import { AppMetadata } from '../provider/interface'; | ||
interface RPCMessage extends Message { | ||
@@ -10,2 +9,6 @@ sender: string; | ||
} | ||
export type EncryptedData = { | ||
iv: ArrayBuffer; | ||
cipherText: ArrayBuffer; | ||
}; | ||
export interface RPCRequestMessage extends RPCMessage { | ||
@@ -26,2 +29,6 @@ content: { | ||
} | ||
type RequestAccountsAction = { | ||
method: 'eth_requestAccounts'; | ||
params: AppMetadata; | ||
}; | ||
export {}; |
@@ -1,5 +0,5 @@ | ||
import { Action } from './Action'; | ||
import { RequestArguments } from '../provider/interface'; | ||
export type RPCRequest = { | ||
action: Action; | ||
action: RequestArguments; | ||
chainId: number; | ||
}; |
@@ -1,4 +0,8 @@ | ||
import { ActionResult } from './ActionResult'; | ||
import { SerializedEthereumRpcError } from '../error'; | ||
export type RPCResponse<T> = { | ||
result: ActionResult<T>; | ||
result: { | ||
value: T; | ||
} | { | ||
error: SerializedEthereumRpcError; | ||
}; | ||
data?: { | ||
@@ -5,0 +9,0 @@ chains?: { |
import { EventEmitter } from 'eventemitter3'; | ||
import { Method } from './method'; | ||
export interface RequestArguments { | ||
readonly method: string; | ||
readonly method: Method | string; | ||
readonly params?: readonly unknown[] | object; | ||
@@ -5,0 +6,0 @@ } |
@@ -11,4 +11,4 @@ declare const mapping: { | ||
export type MethodCategory = keyof typeof mapping; | ||
export type Method<C extends MethodCategory> = (typeof mapping)[C][number]; | ||
export type Method<C extends MethodCategory = MethodCategory> = (typeof mapping)[C][number]; | ||
export declare function determineMethodCategory(method: string): MethodCategory | undefined; | ||
export {}; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.SCWKeyManager = void 0; | ||
const Cipher_1 = require("../../core/message/Cipher"); | ||
const ScopedLocalStorage_1 = require("../../core/storage/ScopedLocalStorage"); | ||
const cipher_1 = require("../../util/cipher"); | ||
const ScopedLocalStorage_1 = require("../../util/ScopedLocalStorage"); | ||
const OWN_PRIVATE_KEY = { | ||
@@ -51,3 +51,3 @@ storageKey: 'ownPrivateKey', | ||
async generateKeyPair() { | ||
const newKeyPair = await (0, Cipher_1.generateKeyPair)(); | ||
const newKeyPair = await (0, cipher_1.generateKeyPair)(); | ||
this.ownPrivateKey = newKeyPair.privateKey; | ||
@@ -74,3 +74,3 @@ this.ownPublicKey = newKeyPair.publicKey; | ||
return; | ||
this.sharedSecret = await (0, Cipher_1.deriveSharedSecret)(this.ownPrivateKey, this.peerPublicKey); | ||
this.sharedSecret = await (0, cipher_1.deriveSharedSecret)(this.ownPrivateKey, this.peerPublicKey); | ||
} | ||
@@ -83,6 +83,6 @@ } | ||
return null; | ||
return (0, Cipher_1.importKeyFromHexString)(item.keyType, key); | ||
return (0, cipher_1.importKeyFromHexString)(item.keyType, key); | ||
} | ||
async storeKey(item, key) { | ||
const hexString = await (0, Cipher_1.exportKeyToHexString)(item.keyType, key); | ||
const hexString = await (0, cipher_1.exportKeyToHexString)(item.keyType, key); | ||
this.storage.setItem(item.storageKey, hexString); | ||
@@ -89,0 +89,0 @@ } |
@@ -8,5 +8,4 @@ "use strict"; | ||
const message_1 = require("../../core/message"); | ||
const Action_1 = require("../../core/message/Action"); | ||
const Cipher_1 = require("../../core/message/Cipher"); | ||
const util_1 = require("../../core/util"); | ||
const util_1 = require("../../core/type/util"); | ||
const cipher_1 = require("../../util/cipher"); | ||
class SCWSigner { | ||
@@ -30,3 +29,3 @@ constructor(params) { | ||
handshake: { | ||
method: Action_1.SupportedEthereumMethods.EthRequestAccounts, | ||
method: 'eth_requestAccounts', | ||
params: this.metadata, | ||
@@ -39,6 +38,6 @@ }, | ||
throw response.content.failure; | ||
const peerPublicKey = await (0, Cipher_1.importKeyFromHexString)('public', response.sender); | ||
const peerPublicKey = await (0, cipher_1.importKeyFromHexString)('public', response.sender); | ||
await this.keyManager.setPeerPublicKey(peerPublicKey); | ||
const decrypted = await this.decryptResponseMessage(response); | ||
this.updateInternalState({ method: Action_1.SupportedEthereumMethods.EthRequestAccounts }, decrypted); | ||
this.updateInternalState({ method: 'eth_requestAccounts' }, decrypted); | ||
const result = decrypted.result; | ||
@@ -72,3 +71,3 @@ if ('error' in result) | ||
switch (request.method) { | ||
case Action_1.SupportedEthereumMethods.WalletSwitchEthereumChain: { | ||
case 'wallet_switchEthereumChain': { | ||
const params = request.params; | ||
@@ -84,3 +83,3 @@ if (!params || !((_a = params[0]) === null || _a === void 0 ? void 0 : _a.chainId)) { | ||
} | ||
case Action_1.SupportedEthereumMethods.WalletGetCapabilities: { | ||
case 'wallet_getCapabilities': { | ||
const walletCapabilities = this.stateManager.walletCapabilities; | ||
@@ -102,3 +101,3 @@ if (!walletCapabilities) { | ||
} | ||
const encrypted = await (0, Cipher_1.encryptContent)({ | ||
const encrypted = await (0, cipher_1.encryptContent)({ | ||
action: request, | ||
@@ -112,3 +111,3 @@ chainId: this.stateManager.activeChain.id, | ||
async createRequestMessage(content) { | ||
const publicKey = await (0, Cipher_1.exportKeyToHexString)('public', await this.keyManager.getOwnPublicKey()); | ||
const publicKey = await (0, cipher_1.exportKeyToHexString)('public', await this.keyManager.getOwnPublicKey()); | ||
return (0, message_1.createMessage)({ | ||
@@ -130,3 +129,3 @@ sender: publicKey, | ||
} | ||
return (0, Cipher_1.decryptContent)(content.encrypted, sharedSecret); | ||
return (0, cipher_1.decryptContent)(content.encrypted, sharedSecret); | ||
} | ||
@@ -147,3 +146,3 @@ updateInternalState(request, response) { | ||
switch (request.method) { | ||
case Action_1.SupportedEthereumMethods.EthRequestAccounts: { | ||
case 'eth_requestAccounts': { | ||
const accounts = result.value; | ||
@@ -153,3 +152,3 @@ this.stateManager.updateAccounts(accounts); | ||
} | ||
case Action_1.SupportedEthereumMethods.WalletSwitchEthereumChain: { | ||
case 'wallet_switchEthereumChain': { | ||
// "return null if the request was successful" | ||
@@ -156,0 +155,0 @@ // https://eips.ethereum.org/EIPS/eip-3326#wallet_switchethereumchain |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.SCWStateManager = void 0; | ||
const ScopedLocalStorage_1 = require("../../core/storage/ScopedLocalStorage"); | ||
const ScopedLocalStorage_1 = require("../../util/ScopedLocalStorage"); | ||
const ACCOUNTS_KEY = 'accounts'; | ||
@@ -6,0 +6,0 @@ const ACTIVE_CHAIN_STORAGE_KEY = 'activeChain'; |
@@ -20,4 +20,3 @@ "use strict"; | ||
const message_1 = require("../core/message"); | ||
const ConfigMessage_1 = require("../core/message/ConfigMessage"); | ||
const ScopedLocalStorage_1 = require("../core/storage/ScopedLocalStorage"); | ||
const ScopedLocalStorage_1 = require("../util/ScopedLocalStorage"); | ||
const SIGNER_TYPE_KEY = 'SignerType'; | ||
@@ -69,3 +68,3 @@ class SignHandler { | ||
const message = (0, message_1.createMessage)({ | ||
event: ConfigMessage_1.ConfigEvent.SelectSignerType, | ||
event: message_1.ConfigEvent.SelectSignerType, | ||
data: this.preference, | ||
@@ -90,3 +89,3 @@ }); | ||
switch (message.event) { | ||
case ConfigMessage_1.ConfigEvent.WalletLinkSessionRequest: | ||
case message_1.ConfigEvent.WalletLinkSessionRequest: | ||
if (!this.walletlinkSigner) { | ||
@@ -93,0 +92,0 @@ this.walletlinkSigner = this.initSigner('walletlink'); |
@@ -5,3 +5,3 @@ "use strict"; | ||
exports.WalletLinkCipher = void 0; | ||
const util_1 = require("../../../../core/util"); | ||
const util_1 = require("../../../../core/type/util"); | ||
class WalletLinkCipher { | ||
@@ -8,0 +8,0 @@ // @param secret hex representation of 32-byte secret |
@@ -1,2 +0,1 @@ | ||
import { DiagnosticLogger } from '../DiagnosticLogger'; | ||
import { WalletLinkEventData, WalletLinkResponseEventData } from '../type/WalletLinkEventData'; | ||
@@ -16,3 +15,2 @@ import { WalletLinkSession } from '../type/WalletLinkSession'; | ||
listener: WalletLinkConnectionUpdateListener; | ||
diagnostic?: DiagnosticLogger; | ||
WebSocketClass?: typeof WebSocket; | ||
@@ -29,3 +27,2 @@ } | ||
private listener?; | ||
private diagnostic?; | ||
private cipher; | ||
@@ -41,3 +38,3 @@ private ws; | ||
*/ | ||
constructor({ session, linkAPIUrl, listener, diagnostic, WebSocketClass, }: WalletLinkConnectionParams); | ||
constructor({ session, linkAPIUrl, listener, WebSocketClass, }: WalletLinkConnectionParams); | ||
/** | ||
@@ -44,0 +41,0 @@ * Make a connection to the server |
@@ -5,5 +5,3 @@ "use strict"; | ||
exports.WalletLinkConnection = void 0; | ||
const DiagnosticLogger_1 = require("../DiagnosticLogger"); | ||
const RelayAbstract_1 = require("../RelayAbstract"); | ||
const WalletLinkSession_1 = require("../type/WalletLinkSession"); | ||
const constants_1 = require("../constants"); | ||
const WalletLinkCipher_1 = require("./WalletLinkCipher"); | ||
@@ -26,3 +24,3 @@ const WalletLinkHTTP_1 = require("./WalletLinkHTTP"); | ||
*/ | ||
constructor({ session, linkAPIUrl, listener, diagnostic, WebSocketClass = WebSocket, }) { | ||
constructor({ session, linkAPIUrl, listener, WebSocketClass = WebSocket, }) { | ||
this.destroyed = false; | ||
@@ -66,46 +64,30 @@ this.lastHeartbeatResponse = 0; | ||
this.handleDestroyed = (__destroyed) => { | ||
var _a, _b; | ||
var _a; | ||
if (__destroyed !== '1') | ||
return; | ||
(_a = this.listener) === null || _a === void 0 ? void 0 : _a.resetAndReload(); | ||
(_b = this.diagnostic) === null || _b === void 0 ? void 0 : _b.log(DiagnosticLogger_1.EVENTS.METADATA_DESTROYED, { | ||
alreadyDestroyed: this.isDestroyed, | ||
sessionIdHash: WalletLinkSession_1.WalletLinkSession.hash(this.session.id), | ||
}); | ||
}; | ||
this.handleAccountUpdated = async (encryptedEthereumAddress) => { | ||
var _a, _b; | ||
try { | ||
var _a; | ||
{ | ||
const address = await this.cipher.decrypt(encryptedEthereumAddress); | ||
(_a = this.listener) === null || _a === void 0 ? void 0 : _a.accountUpdated(address); | ||
} | ||
catch (_c) { | ||
(_b = this.diagnostic) === null || _b === void 0 ? void 0 : _b.log(DiagnosticLogger_1.EVENTS.GENERAL_ERROR, { | ||
message: 'Had error decrypting', | ||
value: 'selectedAddress', | ||
}); | ||
} | ||
}; | ||
this.handleMetadataUpdated = async (key, encryptedMetadataValue) => { | ||
var _a, _b; | ||
try { | ||
var _a; | ||
{ | ||
const decryptedValue = await this.cipher.decrypt(encryptedMetadataValue); | ||
(_a = this.listener) === null || _a === void 0 ? void 0 : _a.metadataUpdated(key, decryptedValue); | ||
} | ||
catch (_c) { | ||
(_b = this.diagnostic) === null || _b === void 0 ? void 0 : _b.log(DiagnosticLogger_1.EVENTS.GENERAL_ERROR, { | ||
message: 'Had error decrypting', | ||
value: key, | ||
}); | ||
} | ||
}; | ||
this.handleWalletUsernameUpdated = async (walletUsername) => { | ||
this.handleMetadataUpdated(RelayAbstract_1.WALLET_USER_NAME_KEY, walletUsername); | ||
this.handleMetadataUpdated(constants_1.WALLET_USER_NAME_KEY, walletUsername); | ||
}; | ||
this.handleAppVersionUpdated = async (appVersion) => { | ||
this.handleMetadataUpdated(RelayAbstract_1.APP_VERSION_KEY, appVersion); | ||
this.handleMetadataUpdated(constants_1.APP_VERSION_KEY, appVersion); | ||
}; | ||
this.handleChainUpdated = async (encryptedChainId, encryptedJsonRpcUrl) => { | ||
var _a, _b; | ||
try { | ||
var _a; | ||
{ | ||
const chainId = await this.cipher.decrypt(encryptedChainId); | ||
@@ -115,21 +97,9 @@ const jsonRpcUrl = await this.cipher.decrypt(encryptedJsonRpcUrl); | ||
} | ||
catch (_c) { | ||
(_b = this.diagnostic) === null || _b === void 0 ? void 0 : _b.log(DiagnosticLogger_1.EVENTS.GENERAL_ERROR, { | ||
message: 'Had error decrypting', | ||
value: 'chainId|jsonRpcUrl', | ||
}); | ||
} | ||
}; | ||
this.session = session; | ||
this.cipher = new WalletLinkCipher_1.WalletLinkCipher(session.secret); | ||
this.diagnostic = diagnostic; | ||
this.listener = listener; | ||
const ws = new WalletLinkWebSocket_1.WalletLinkWebSocket(`${linkAPIUrl}/rpc`, WebSocketClass); | ||
ws.setConnectionStateListener(async (state) => { | ||
var _a; | ||
// attempt to reconnect every 5 seconds when disconnected | ||
(_a = this.diagnostic) === null || _a === void 0 ? void 0 : _a.log(DiagnosticLogger_1.EVENTS.CONNECTED_STATE_CHANGE, { | ||
state, | ||
sessionIdHash: WalletLinkSession_1.WalletLinkSession.hash(session.id), | ||
}); | ||
let connected = false; | ||
@@ -163,3 +133,3 @@ switch (state) { | ||
} | ||
catch (_b) { | ||
catch (_a) { | ||
/* empty */ | ||
@@ -189,3 +159,3 @@ } | ||
ws.setIncomingDataListener((m) => { | ||
var _a, _b, _c; | ||
var _a; | ||
switch (m.type) { | ||
@@ -200,8 +170,2 @@ // handle server's heartbeat responses | ||
const linked = m.type === 'IsLinkedOK' ? m.linked : undefined; | ||
(_a = this.diagnostic) === null || _a === void 0 ? void 0 : _a.log(DiagnosticLogger_1.EVENTS.LINKED, { | ||
sessionIdHash: WalletLinkSession_1.WalletLinkSession.hash(session.id), | ||
linked, | ||
type: m.type, | ||
onlineGuests: m.onlineGuests, | ||
}); | ||
this.linked = linked || m.onlineGuests > 0; | ||
@@ -213,6 +177,2 @@ break; | ||
case 'SessionConfigUpdated': { | ||
(_b = this.diagnostic) === null || _b === void 0 ? void 0 : _b.log(DiagnosticLogger_1.EVENTS.SESSION_CONFIG_RECEIVED, { | ||
sessionIdHash: WalletLinkSession_1.WalletLinkSession.hash(session.id), | ||
metadata_keys: m && m.metadata ? Object.keys(m.metadata) : undefined, | ||
}); | ||
this.handleSessionMetadataUpdated(m.metadata); | ||
@@ -228,3 +188,3 @@ break; | ||
if (m.id !== undefined) { | ||
(_c = this.requestResolutions.get(m.id)) === null || _c === void 0 ? void 0 : _c(m); | ||
(_a = this.requestResolutions.get(m.id)) === null || _a === void 0 ? void 0 : _a(m); | ||
} | ||
@@ -239,9 +199,5 @@ }); | ||
connect() { | ||
var _a; | ||
if (this.destroyed) { | ||
throw new Error('instance is destroyed'); | ||
} | ||
(_a = this.diagnostic) === null || _a === void 0 ? void 0 : _a.log(DiagnosticLogger_1.EVENTS.STARTED_CONNECTING, { | ||
sessionIdHash: WalletLinkSession_1.WalletLinkSession.hash(this.session.id), | ||
}); | ||
this.ws.connect(); | ||
@@ -254,8 +210,4 @@ } | ||
destroy() { | ||
var _a; | ||
this.destroyed = true; | ||
this.ws.disconnect(); | ||
(_a = this.diagnostic) === null || _a === void 0 ? void 0 : _a.log(DiagnosticLogger_1.EVENTS.DISCONNECTED, { | ||
sessionIdHash: WalletLinkSession_1.WalletLinkSession.hash(this.session.id), | ||
}); | ||
this.listener = undefined; | ||
@@ -312,7 +264,7 @@ } | ||
async handleIncomingEvent(m) { | ||
var _a, _b; | ||
var _a; | ||
if (m.type !== 'Event' || m.event !== 'Web3Response') { | ||
return; | ||
} | ||
try { | ||
{ | ||
const decryptedData = await this.cipher.decrypt(m.data); | ||
@@ -324,8 +276,2 @@ const message = JSON.parse(decryptedData); | ||
} | ||
catch (_c) { | ||
(_b = this.diagnostic) === null || _b === void 0 ? void 0 : _b.log(DiagnosticLogger_1.EVENTS.GENERAL_ERROR, { | ||
message: 'Had error decrypting', | ||
value: 'incomingEvent', | ||
}); | ||
} | ||
} | ||
@@ -332,0 +278,0 @@ async checkUnseenEvents() { |
@@ -1,144 +0,2 @@ | ||
import { RelayAbstract } from '../RelayAbstract'; | ||
import { Web3Method } from '../type/Web3Method'; | ||
import { Web3Response } from '../type/Web3Response'; | ||
import { AddressString, HexString } from '../../../../core/type'; | ||
export declare class MockRelayClass extends RelayAbstract { | ||
constructor(); | ||
resetAndReload(): void; | ||
requestEthereumAccounts(): { | ||
cancel: () => void; | ||
promise: Promise<{ | ||
method: "requestEthereumAccounts"; | ||
result: AddressString[]; | ||
} | { | ||
method: unknown; | ||
errorCode?: number | undefined; | ||
errorMessage: string; | ||
}>; | ||
}; | ||
addEthereumChain(): { | ||
cancel: () => void; | ||
promise: Promise<{ | ||
method: "addEthereumChain"; | ||
result: { | ||
isApproved: boolean; | ||
rpcUrl: string; | ||
}; | ||
} | { | ||
method: unknown; | ||
errorCode?: number | undefined; | ||
errorMessage: string; | ||
}>; | ||
}; | ||
watchAsset(): { | ||
cancel: () => void; | ||
promise: Promise<{ | ||
method: "watchAsset"; | ||
result: boolean; | ||
} | { | ||
method: unknown; | ||
errorCode?: number | undefined; | ||
errorMessage: string; | ||
}>; | ||
}; | ||
switchEthereumChain(): { | ||
cancel: () => void; | ||
promise: Promise<{ | ||
method: "switchEthereumChain"; | ||
result: { | ||
isApproved: boolean; | ||
rpcUrl: string; | ||
}; | ||
} | { | ||
method: unknown; | ||
errorCode?: number | undefined; | ||
errorMessage: string; | ||
}>; | ||
}; | ||
signEthereumMessage(): { | ||
cancel: () => void; | ||
promise: Promise<{ | ||
method: "signEthereumMessage"; | ||
result: HexString; | ||
} | { | ||
method: unknown; | ||
errorCode?: number | undefined; | ||
errorMessage: string; | ||
}>; | ||
}; | ||
ethereumAddressFromSignedMessage(): { | ||
cancel: () => void; | ||
promise: Promise<{ | ||
method: "ethereumAddressFromSignedMessage"; | ||
result: AddressString; | ||
} | { | ||
method: unknown; | ||
errorCode?: number | undefined; | ||
errorMessage: string; | ||
}>; | ||
}; | ||
signEthereumTransaction(): { | ||
cancel: () => void; | ||
promise: Promise<{ | ||
method: "signEthereumTransaction"; | ||
result: HexString; | ||
} | { | ||
method: unknown; | ||
errorCode?: number | undefined; | ||
errorMessage: string; | ||
}>; | ||
}; | ||
signAndSubmitEthereumTransaction(): { | ||
cancel: () => void; | ||
promise: Promise<{ | ||
method: "submitEthereumTransaction"; | ||
result: HexString; | ||
} | { | ||
method: unknown; | ||
errorCode?: number | undefined; | ||
errorMessage: string; | ||
}>; | ||
}; | ||
submitEthereumTransaction(): { | ||
cancel: () => void; | ||
promise: Promise<{ | ||
method: "submitEthereumTransaction"; | ||
result: HexString; | ||
} | { | ||
method: unknown; | ||
errorCode?: number | undefined; | ||
errorMessage: string; | ||
}>; | ||
}; | ||
scanQRCode(): { | ||
cancel: () => void; | ||
promise: Promise<{ | ||
method: "scanQRCode"; | ||
result: string; | ||
} | { | ||
method: unknown; | ||
errorCode?: number | undefined; | ||
errorMessage: string; | ||
}>; | ||
}; | ||
genericRequest(): { | ||
cancel: () => void; | ||
promise: Promise<{ | ||
method: "generic"; | ||
result: string; | ||
} | { | ||
method: unknown; | ||
errorCode?: number | undefined; | ||
errorMessage: string; | ||
}>; | ||
}; | ||
sendRequest<_, T extends Web3Method>(): { | ||
cancel: () => void; | ||
promise: Promise<Web3Response<T>>; | ||
}; | ||
setAppInfo(): void; | ||
setAccountsCallback(): void; | ||
setChainCallback(): void; | ||
setDappDefaultChainCallback(): void; | ||
attachUI(): void; | ||
} | ||
import { WalletLinkRelay } from '../WalletLinkRelay'; | ||
export declare function mockedWalletLinkRelay(): WalletLinkRelay; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.MockRelayClass = void 0; | ||
const RelayAbstract_1 = require("../RelayAbstract"); | ||
exports.mockedWalletLinkRelay = void 0; | ||
const fixtures_1 = require("./fixtures"); | ||
const type_1 = require("../../../../core/type"); | ||
function mockedWalletLinkRelay() { | ||
return mock; | ||
} | ||
exports.mockedWalletLinkRelay = mockedWalletLinkRelay; | ||
function makeMockReturn(response) { | ||
return { cancel: () => { }, promise: Promise.resolve(response) }; | ||
return Promise.resolve(response); | ||
} | ||
class MockRelayClass extends RelayAbstract_1.RelayAbstract { | ||
constructor() { | ||
super(); | ||
this.requestEthereumAccounts = this.requestEthereumAccounts.bind(this); | ||
} | ||
resetAndReload() { } | ||
const mock = { | ||
resetAndReload() { }, | ||
requestEthereumAccounts() { | ||
@@ -21,3 +20,3 @@ return makeMockReturn({ | ||
}); | ||
} | ||
}, | ||
addEthereumChain() { | ||
@@ -31,3 +30,3 @@ return makeMockReturn({ | ||
}); | ||
} | ||
}, | ||
watchAsset() { | ||
@@ -38,3 +37,3 @@ return makeMockReturn({ | ||
}); | ||
} | ||
}, | ||
switchEthereumChain() { | ||
@@ -48,3 +47,3 @@ return makeMockReturn({ | ||
}); | ||
} | ||
}, | ||
signEthereumMessage() { | ||
@@ -55,3 +54,3 @@ return makeMockReturn({ | ||
}); | ||
} | ||
}, | ||
ethereumAddressFromSignedMessage() { | ||
@@ -62,3 +61,3 @@ return makeMockReturn({ | ||
}); | ||
} | ||
}, | ||
signEthereumTransaction() { | ||
@@ -69,3 +68,3 @@ return makeMockReturn({ | ||
}); | ||
} | ||
}, | ||
signAndSubmitEthereumTransaction() { | ||
@@ -76,3 +75,3 @@ return makeMockReturn({ | ||
}); | ||
} | ||
}, | ||
submitEthereumTransaction() { | ||
@@ -83,3 +82,3 @@ return makeMockReturn({ | ||
}); | ||
} | ||
}, | ||
scanQRCode() { | ||
@@ -90,3 +89,3 @@ return makeMockReturn({ | ||
}); | ||
} | ||
}, | ||
genericRequest() { | ||
@@ -97,22 +96,21 @@ return makeMockReturn({ | ||
}); | ||
} | ||
}, | ||
sendRequest() { | ||
return { cancel: () => { }, promise: Promise.reject() }; | ||
} | ||
return Promise.reject(); | ||
}, | ||
setAppInfo() { | ||
return; | ||
} | ||
}, | ||
setAccountsCallback() { | ||
return; | ||
} | ||
}, | ||
setChainCallback() { | ||
return; | ||
} | ||
}, | ||
setDappDefaultChainCallback() { | ||
return; | ||
} | ||
}, | ||
attachUI() { | ||
return; | ||
} | ||
} | ||
exports.MockRelayClass = MockRelayClass; | ||
}, | ||
}; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.RelayEventManager = void 0; | ||
const util_1 = require("../../../core/util"); | ||
const util_1 = require("../../../core/type/util"); | ||
class RelayEventManager { | ||
@@ -6,0 +6,0 @@ constructor() { |
@@ -1,2 +0,2 @@ | ||
import { ScopedLocalStorage } from '../../../../core/storage/ScopedLocalStorage'; | ||
import { ScopedLocalStorage } from '../../../../util/ScopedLocalStorage'; | ||
export declare class WalletLinkSession { | ||
@@ -10,7 +10,2 @@ private readonly _id; | ||
static load(storage: ScopedLocalStorage): WalletLinkSession | null; | ||
/** | ||
* Takes in a session ID and returns the sha256 hash of it. | ||
* @param sessionId session ID | ||
*/ | ||
static hash(sessionId: string): string; | ||
get id(): string; | ||
@@ -17,0 +12,0 @@ get secret(): string; |
@@ -6,3 +6,3 @@ "use strict"; | ||
const sha_js_1 = require("sha.js"); | ||
const util_1 = require("../../../../core/util"); | ||
const util_1 = require("../../../../core/type/util"); | ||
const STORAGE_KEY_SESSION_ID = 'session:id'; | ||
@@ -30,9 +30,2 @@ const STORAGE_KEY_SESSION_SECRET = 'session:secret'; | ||
} | ||
/** | ||
* Takes in a session ID and returns the sha256 hash of it. | ||
* @param sessionId session ID | ||
*/ | ||
static hash(sessionId) { | ||
return new sha_js_1.sha256().update(sessionId).digest('hex'); | ||
} | ||
get id() { | ||
@@ -39,0 +32,0 @@ return this._id; |
/// <reference types="node" /> | ||
import { WalletLinkConnection, WalletLinkConnectionUpdateListener } from './connection/WalletLinkConnection'; | ||
import { DiagnosticLogger } from './DiagnosticLogger'; | ||
import { CancelablePromise, RelayAbstract } from './RelayAbstract'; | ||
import { EthereumTransactionParams } from './type/EthereumTransactionParams'; | ||
@@ -13,11 +11,10 @@ import { WalletLinkEventData, WalletLinkResponseEventData } from './type/WalletLinkEventData'; | ||
import { WLMobileRelayUI } from './ui/WLMobileRelayUI'; | ||
import { ScopedLocalStorage } from '../../../core/storage/ScopedLocalStorage'; | ||
import { AddressString, IntNumber, RegExpString } from '../../../core/type'; | ||
export interface WalletLinkRelayOptions { | ||
import { ScopedLocalStorage } from '../../../util/ScopedLocalStorage'; | ||
interface WalletLinkRelayOptions { | ||
linkAPIUrl: string; | ||
storage: ScopedLocalStorage; | ||
diagnosticLogger?: DiagnosticLogger; | ||
reloadOnDisconnect?: boolean; | ||
} | ||
export declare class WalletLinkRelay extends RelayAbstract implements WalletLinkConnectionUpdateListener { | ||
export declare class WalletLinkRelay implements WalletLinkConnectionUpdateListener { | ||
private static accountRequestCallbackIds; | ||
@@ -28,3 +25,2 @@ private readonly linkAPIUrl; | ||
private readonly relayEventManager; | ||
protected readonly diagnostic?: DiagnosticLogger; | ||
protected connection: WalletLinkConnection; | ||
@@ -57,12 +53,12 @@ private accountsCallback; | ||
setStorageItem(key: string, value: string): void; | ||
signEthereumMessage(message: Buffer, address: AddressString, addPrefix: boolean, typedDataJson?: string | null): CancelablePromise<Web3Response<"signEthereumMessage">>; | ||
ethereumAddressFromSignedMessage(message: Buffer, signature: Buffer, addPrefix: boolean): CancelablePromise<Web3Response<"ethereumAddressFromSignedMessage">>; | ||
signEthereumTransaction(params: EthereumTransactionParams): CancelablePromise<Web3Response<"signEthereumTransaction">>; | ||
signAndSubmitEthereumTransaction(params: EthereumTransactionParams): CancelablePromise<Web3Response<"submitEthereumTransaction">>; | ||
submitEthereumTransaction(signedTransaction: Buffer, chainId: IntNumber): CancelablePromise<Web3Response<"submitEthereumTransaction">>; | ||
scanQRCode(regExp: RegExpString): CancelablePromise<Web3Response<"scanQRCode">>; | ||
signEthereumMessage(message: Buffer, address: AddressString, addPrefix: boolean, typedDataJson?: string | null): Promise<Web3Response<"signEthereumMessage">>; | ||
ethereumAddressFromSignedMessage(message: Buffer, signature: Buffer, addPrefix: boolean): Promise<Web3Response<"ethereumAddressFromSignedMessage">>; | ||
signEthereumTransaction(params: EthereumTransactionParams): Promise<Web3Response<"signEthereumTransaction">>; | ||
signAndSubmitEthereumTransaction(params: EthereumTransactionParams): Promise<Web3Response<"submitEthereumTransaction">>; | ||
submitEthereumTransaction(signedTransaction: Buffer, chainId: IntNumber): Promise<Web3Response<"submitEthereumTransaction">>; | ||
scanQRCode(regExp: RegExpString): Promise<Web3Response<"scanQRCode">>; | ||
getWalletLinkSession(): WalletLinkSession; | ||
genericRequest(data: object, action: string): CancelablePromise<Web3Response<"generic">>; | ||
sendGenericMessage(request: Web3Request<'generic'>): CancelablePromise<Web3Response<'generic'>>; | ||
sendRequest<RequestMethod extends SupportedWeb3Method, ResponseMethod extends SupportedWeb3Method = RequestMethod, Response = Web3Response<ResponseMethod>>(request: Web3Request<RequestMethod>): CancelablePromise<Response>; | ||
genericRequest(data: object, action: string): Promise<Web3Response<"generic">>; | ||
sendGenericMessage(request: Web3Request<'generic'>): Promise<Web3Response<'generic'>>; | ||
sendRequest<RequestMethod extends SupportedWeb3Method, ResponseMethod extends SupportedWeb3Method = RequestMethod, Response = Web3Response<ResponseMethod>>(request: Web3Request<RequestMethod>): Promise<Response>; | ||
setAccountsCallback(accountsCallback: (accounts: string[], isDisconnect?: boolean) => void): void; | ||
@@ -78,7 +74,4 @@ setChainCallback(chainCallback: (chainId: string, jsonRpcUrl: string) => void): void; | ||
private invokeCallback; | ||
requestEthereumAccounts(): { | ||
promise: Promise<Web3Response<"requestEthereumAccounts">>; | ||
cancel: (error?: Error) => void; | ||
}; | ||
watchAsset(type: string, address: string, symbol?: string, decimals?: number, image?: string, chainId?: string): CancelablePromise<Web3Response<'watchAsset'>>; | ||
requestEthereumAccounts(): Promise<Web3Response<"requestEthereumAccounts">>; | ||
watchAsset(type: string, address: string, symbol?: string, decimals?: number, image?: string, chainId?: string): Promise<Web3Response<'watchAsset'>>; | ||
addEthereumChain(chainId: string, rpcUrls: string[], iconUrls: string[], blockExplorerUrls: string[], chainName?: string, nativeCurrency?: { | ||
@@ -88,8 +81,5 @@ name: string; | ||
decimals: number; | ||
}): { | ||
promise: Promise<Web3Response<"addEthereumChain">>; | ||
cancel: (error?: Error) => void; | ||
}; | ||
switchEthereumChain(chainId: string, address?: string): CancelablePromise<Web3Response<'switchEthereumChain'>>; | ||
private getSessionIdHash; | ||
}): Promise<Web3Response<"addEthereumChain">>; | ||
switchEthereumChain(chainId: string, address?: string): Promise<Web3Response<'switchEthereumChain'>>; | ||
} | ||
export {}; |
@@ -6,4 +6,3 @@ "use strict"; | ||
const WalletLinkConnection_1 = require("./connection/WalletLinkConnection"); | ||
const DiagnosticLogger_1 = require("./DiagnosticLogger"); | ||
const RelayAbstract_1 = require("./RelayAbstract"); | ||
const constants_1 = require("./constants"); | ||
const RelayEventManager_1 = require("./RelayEventManager"); | ||
@@ -16,7 +15,6 @@ const WalletLinkSession_1 = require("./type/WalletLinkSession"); | ||
const error_1 = require("../../../core/error"); | ||
const util_2 = require("../../../core/util"); | ||
class WalletLinkRelay extends RelayAbstract_1.RelayAbstract { | ||
const util_2 = require("../../../core/type/util"); | ||
class WalletLinkRelay { | ||
constructor(options) { | ||
var _a; | ||
super(); | ||
this.accountsCallback = null; | ||
@@ -30,5 +28,4 @@ this.chainCallbackParams = { chainId: '', jsonRpcUrl: '' }; // to implement distinctUntilChanged | ||
this.linkedUpdated = (linked) => { | ||
var _a; | ||
this.isLinked = linked; | ||
const cachedAddresses = this.storage.getItem(RelayAbstract_1.LOCAL_STORAGE_ADDRESSES_KEY); | ||
const cachedAddresses = this.storage.getItem(constants_1.LOCAL_STORAGE_ADDRESSES_KEY); | ||
if (linked) { | ||
@@ -44,6 +41,2 @@ // Only set linked session variable one way | ||
this.isUnlinkedErrorState = true; | ||
const sessionIdHash = this.getSessionIdHash(); | ||
(_a = this.diagnostic) === null || _a === void 0 ? void 0 : _a.log(DiagnosticLogger_1.EVENTS.UNLINKED_ERROR_STATE, { | ||
sessionIdHash, | ||
}); | ||
} | ||
@@ -97,3 +90,2 @@ } | ||
this.relayEventManager = new RelayEventManager_1.RelayEventManager(); | ||
this.diagnostic = options.diagnosticLogger; | ||
this._reloadOnDisconnect = (_a = options.reloadOnDisconnect) !== null && _a !== void 0 ? _a : false; | ||
@@ -104,7 +96,6 @@ this.ui = ui; | ||
const session = WalletLinkSession_1.WalletLinkSession.load(this.storage) || new WalletLinkSession_1.WalletLinkSession(this.storage).save(); | ||
const { linkAPIUrl, diagnostic } = this; | ||
const { linkAPIUrl } = this; | ||
const connection = new WalletLinkConnection_1.WalletLinkConnection({ | ||
session, | ||
linkAPIUrl, | ||
diagnostic, | ||
listener: this, | ||
@@ -125,8 +116,2 @@ }); | ||
.then(() => { | ||
var _a, _b; | ||
(_a = this.diagnostic) === null || _a === void 0 ? void 0 : _a.log(DiagnosticLogger_1.EVENTS.SESSION_STATE_CHANGE, { | ||
method: 'relay::resetAndReload', | ||
sessionMetadataChange: '__destroyed, 1', | ||
sessionIdHash: this.getSessionIdHash(), | ||
}); | ||
this.connection.destroy(); | ||
@@ -145,8 +130,2 @@ /** | ||
} | ||
else if (storedSession) { | ||
(_b = this.diagnostic) === null || _b === void 0 ? void 0 : _b.log(DiagnosticLogger_1.EVENTS.SKIPPED_CLEARING_SESSION, { | ||
sessionIdHash: this.getSessionIdHash(), | ||
storedSessionIdHash: WalletLinkSession_1.WalletLinkSession.hash(storedSession.id), | ||
}); | ||
} | ||
if (this._reloadOnDisconnect) { | ||
@@ -165,10 +144,3 @@ this.ui.reloadUI(); | ||
}) | ||
.catch((err) => { | ||
var _a; | ||
(_a = this.diagnostic) === null || _a === void 0 ? void 0 : _a.log(DiagnosticLogger_1.EVENTS.FAILURE, { | ||
method: 'relay::resetAndReload', | ||
message: `failed to reset and reload with ${err}`, | ||
sessionIdHash: this.getSessionIdHash(), | ||
}); | ||
}); | ||
.catch((_) => { }); | ||
} | ||
@@ -286,3 +258,3 @@ setAppInfo(appName, appLogoUrl) { | ||
}; | ||
const promise = new Promise((resolve, reject) => { | ||
return new Promise((resolve, reject) => { | ||
{ | ||
@@ -304,3 +276,2 @@ hideSnackbarItem = this.ui.showConnecting({ | ||
}); | ||
return { promise, cancel }; | ||
} | ||
@@ -317,23 +288,5 @@ setAccountsCallback(accountsCallback) { | ||
publishWeb3RequestEvent(id, request) { | ||
var _a; | ||
const message = { type: 'WEB3_REQUEST', id, request }; | ||
const storedSession = WalletLinkSession_1.WalletLinkSession.load(this.storage); | ||
(_a = this.diagnostic) === null || _a === void 0 ? void 0 : _a.log(DiagnosticLogger_1.EVENTS.WEB3_REQUEST, { | ||
eventId: message.id, | ||
method: `relay::${request.method}`, | ||
sessionIdHash: this.getSessionIdHash(), | ||
storedSessionIdHash: storedSession ? WalletLinkSession_1.WalletLinkSession.hash(storedSession.id) : '', | ||
isSessionMismatched: ((storedSession === null || storedSession === void 0 ? void 0 : storedSession.id) !== this._session.id).toString(), | ||
}); | ||
this.publishEvent('Web3Request', message, true) | ||
.then((_) => { | ||
var _a; | ||
(_a = this.diagnostic) === null || _a === void 0 ? void 0 : _a.log(DiagnosticLogger_1.EVENTS.WEB3_REQUEST_PUBLISHED, { | ||
eventId: message.id, | ||
method: `relay::${request.method}`, | ||
sessionIdHash: this.getSessionIdHash(), | ||
storedSessionIdHash: storedSession ? WalletLinkSession_1.WalletLinkSession.hash(storedSession.id) : '', | ||
isSessionMismatched: ((storedSession === null || storedSession === void 0 ? void 0 : storedSession.id) !== this._session.id).toString(), | ||
}); | ||
}) | ||
.then((_) => { }) | ||
.catch((err) => { | ||
@@ -383,9 +336,3 @@ this.handleWeb3ResponseMessage({ | ||
handleWeb3ResponseMessage(message) { | ||
var _a; | ||
const { response } = message; | ||
(_a = this.diagnostic) === null || _a === void 0 ? void 0 : _a.log(DiagnosticLogger_1.EVENTS.WEB3_RESPONSE, { | ||
eventId: message.id, | ||
method: `relay::${response.method}`, | ||
sessionIdHash: this.getSessionIdHash(), | ||
}); | ||
if (response.method === 'requestEthereumAccounts') { | ||
@@ -427,10 +374,3 @@ WalletLinkRelay.accountRequestCallbackIds.forEach((id) => this.invokeCallback(Object.assign(Object.assign({}, message), { id }))); | ||
const id = (0, util_2.randomBytesHex)(8); | ||
const cancel = (error) => { | ||
this.publishWeb3RequestCanceledEvent(id); | ||
this.handleErrorResponse(id, request.method, error); | ||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment | ||
// @ts-ignore | ||
hideSnackbarItem === null || hideSnackbarItem === void 0 ? void 0 : hideSnackbarItem(); | ||
}; | ||
const promise = new Promise((resolve, reject) => { | ||
return new Promise((resolve, reject) => { | ||
this.relayEventManager.callbacks.set(id, (response) => { | ||
@@ -448,3 +388,2 @@ // eslint-disable-next-line @typescript-eslint/ban-ts-comment | ||
}); | ||
return { promise, cancel }; | ||
} | ||
@@ -479,3 +418,3 @@ watchAsset(type, address, symbol, decimals, image, chainId) { | ||
} | ||
const promise = new Promise((resolve, reject) => { | ||
return new Promise((resolve, reject) => { | ||
this.relayEventManager.callbacks.set(id, (response) => { | ||
@@ -490,3 +429,2 @@ hideSnackbarItem === null || hideSnackbarItem === void 0 ? void 0 : hideSnackbarItem(); | ||
}); | ||
return { cancel, promise }; | ||
} | ||
@@ -519,3 +457,3 @@ addEthereumChain(chainId, rpcUrls, iconUrls, blockExplorerUrls, chainName, nativeCurrency) { | ||
} | ||
const promise = new Promise((resolve, reject) => { | ||
return new Promise((resolve, reject) => { | ||
this.relayEventManager.callbacks.set(id, (response) => { | ||
@@ -530,3 +468,2 @@ hideSnackbarItem === null || hideSnackbarItem === void 0 ? void 0 : hideSnackbarItem(); | ||
}); | ||
return { promise, cancel }; | ||
} | ||
@@ -539,7 +476,3 @@ switchEthereumChain(chainId, address) { | ||
const id = (0, util_2.randomBytesHex)(8); | ||
const cancel = (error) => { | ||
this.publishWeb3RequestCanceledEvent(id); | ||
this.handleErrorResponse(id, request.method, error); | ||
}; | ||
const promise = new Promise((resolve, reject) => { | ||
return new Promise((resolve, reject) => { | ||
this.relayEventManager.callbacks.set(id, (response) => { | ||
@@ -559,9 +492,5 @@ if ((0, Web3Response_1.isErrorResponse)(response) && response.errorCode) { | ||
}); | ||
return { promise, cancel }; | ||
} | ||
getSessionIdHash() { | ||
return WalletLinkSession_1.WalletLinkSession.hash(this._session.id); | ||
} | ||
} | ||
exports.WalletLinkRelay = WalletLinkRelay; | ||
WalletLinkRelay.accountRequestCallbackIds = new Set(); |
@@ -10,3 +10,3 @@ "use strict"; | ||
const eth_eip712_util_1 = __importDefault(require("../../../vendor-js/eth-eip712-util")); | ||
const RelayAbstract_1 = require("./RelayAbstract"); | ||
const constants_1 = require("./constants"); | ||
const RelayEventManager_1 = require("./RelayEventManager"); | ||
@@ -16,4 +16,4 @@ const Web3Response_1 = require("./type/Web3Response"); | ||
const error_1 = require("../../../core/error"); | ||
const ScopedLocalStorage_1 = require("../../../core/storage/ScopedLocalStorage"); | ||
const util_1 = require("../../../core/util"); | ||
const util_1 = require("../../../core/type/util"); | ||
const ScopedLocalStorage_1 = require("../../../util/ScopedLocalStorage"); | ||
const DEFAULT_CHAIN_ID_KEY = 'DefaultChainId'; | ||
@@ -33,3 +33,3 @@ const DEFAULT_JSON_RPC_URL = 'DefaultJsonRpcUrl'; | ||
this._jsonRpcUrlFromOpts = ''; | ||
const cachedAddresses = this._storage.getItem(RelayAbstract_1.LOCAL_STORAGE_ADDRESSES_KEY); | ||
const cachedAddresses = this._storage.getItem(constants_1.LOCAL_STORAGE_ADDRESSES_KEY); | ||
if (cachedAddresses) { | ||
@@ -87,3 +87,3 @@ const addresses = cachedAddresses.split(' '); | ||
const relay = this.initializeRelay(); | ||
const result = await relay.watchAsset(type, address, symbol, decimals, image, chainId === null || chainId === void 0 ? void 0 : chainId.toString()).promise; | ||
const result = await relay.watchAsset(type, address, symbol, decimals, image, chainId === null || chainId === void 0 ? void 0 : chainId.toString()); | ||
if ((0, Web3Response_1.isErrorResponse)(result)) | ||
@@ -100,5 +100,5 @@ return false; | ||
if (!this._isAuthorized()) { | ||
await relay.requestEthereumAccounts().promise; | ||
await relay.requestEthereumAccounts(); | ||
} | ||
const res = await relay.addEthereumChain(chainId.toString(), rpcUrls, iconUrls, blockExplorerUrls, chainName, nativeCurrency).promise; | ||
const res = await relay.addEthereumChain(chainId.toString(), rpcUrls, iconUrls, blockExplorerUrls, chainName, nativeCurrency); | ||
if ((0, Web3Response_1.isErrorResponse)(res)) | ||
@@ -113,3 +113,3 @@ return false; | ||
const relay = this.initializeRelay(); | ||
const res = await relay.switchEthereumChain(chainId.toString(10), this.selectedAddress || undefined).promise; | ||
const res = await relay.switchEthereumChain(chainId.toString(10), this.selectedAddress || undefined); | ||
// backward compatibility | ||
@@ -195,3 +195,3 @@ if ((0, Web3Response_1.isErrorResponse)(res)) { | ||
}); | ||
this._storage.setItem(RelayAbstract_1.LOCAL_STORAGE_ADDRESSES_KEY, newAddresses.join(' ')); | ||
this._storage.setItem(constants_1.LOCAL_STORAGE_ADDRESSES_KEY, newAddresses.join(' ')); | ||
} | ||
@@ -331,4 +331,3 @@ _sendRequestAsync(request) { | ||
const relay = this.initializeRelay(); | ||
const res = await relay.signEthereumMessage(message, address, addPrefix, typedDataJson) | ||
.promise; | ||
const res = await relay.signEthereumMessage(message, address, addPrefix, typedDataJson); | ||
if ((0, Web3Response_1.isErrorResponse)(res)) { | ||
@@ -348,3 +347,3 @@ throw new Error(res.errorMessage); | ||
const relay = this.initializeRelay(); | ||
const res = await relay.ethereumAddressFromSignedMessage(message, signature, addPrefix).promise; | ||
const res = await relay.ethereumAddressFromSignedMessage(message, signature, addPrefix); | ||
if ((0, Web3Response_1.isErrorResponse)(res)) { | ||
@@ -386,3 +385,3 @@ throw new Error(res.errorMessage); | ||
const relay = this.initializeRelay(); | ||
res = await relay.requestEthereumAccounts().promise; | ||
res = await relay.requestEthereumAccounts(); | ||
if ((0, Web3Response_1.isErrorResponse)(res)) { | ||
@@ -431,3 +430,3 @@ throw new Error(res.errorMessage); | ||
const relay = this.initializeRelay(); | ||
const res = await relay.signEthereumTransaction(tx).promise; | ||
const res = await relay.signEthereumTransaction(tx); | ||
if ((0, Web3Response_1.isErrorResponse)(res)) { | ||
@@ -448,3 +447,3 @@ throw new Error(res.errorMessage); | ||
const relay = this.initializeRelay(); | ||
const res = await relay.submitEthereumTransaction(signedTransaction, this.getChainId()).promise; | ||
const res = await relay.submitEthereumTransaction(signedTransaction, this.getChainId()); | ||
if ((0, Web3Response_1.isErrorResponse)(res)) { | ||
@@ -460,3 +459,3 @@ throw new Error(res.errorMessage); | ||
const relay = this.initializeRelay(); | ||
const res = await relay.signAndSubmitEthereumTransaction(tx).promise; | ||
const res = await relay.signAndSubmitEthereumTransaction(tx); | ||
if ((0, Web3Response_1.isErrorResponse)(res)) { | ||
@@ -463,0 +462,0 @@ throw new Error(res.errorMessage); |
@@ -6,3 +6,3 @@ "use strict"; | ||
const constants_1 = require("../../core/constants"); | ||
const ConfigMessage_1 = require("../../core/message/ConfigMessage"); | ||
const message_1 = require("../../core/message"); | ||
class WLSigner { | ||
@@ -41,3 +41,3 @@ constructor(params) { | ||
this.popupCommunicator.postMessage({ | ||
event: ConfigMessage_1.ConfigEvent.WalletLinkUpdate, | ||
event: message_1.ConfigEvent.WalletLinkUpdate, | ||
data, | ||
@@ -44,0 +44,0 @@ }); |
@@ -1,1 +0,1 @@ | ||
export declare const LIB_VERSION = "4.0.0-rc.1"; | ||
export declare const LIB_VERSION = "4.0.0-rc.2"; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.LIB_VERSION = void 0; | ||
exports.LIB_VERSION = '4.0.0-rc.1'; | ||
exports.LIB_VERSION = '4.0.0-rc.2'; |
{ | ||
"name": "@coinbase/wallet-sdk", | ||
"version": "4.0.0-rc.1", | ||
"version": "4.0.0-rc.2", | ||
"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
266430
132
6292