walletlink
Advanced tools
Comparing version 2.2.10 to 2.2.11
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.EthereumChain = void 0; | ||
// TODO: deprecate this class in February 2022 | ||
var EthereumChain; | ||
@@ -5,0 +6,0 @@ (function (EthereumChain) { |
@@ -50,2 +50,3 @@ import SafeEventEmitter from "@metamask/safe-event-emitter"; | ||
private updateProviderInfo; | ||
private addEthereumChain; | ||
private switchEthereumChain; | ||
@@ -64,3 +65,3 @@ setAppInfo(appName: string, appLogoUrl: string | null): void; | ||
scanQRCode(match?: RegExp): Promise<string>; | ||
arbitraryRequest(data: string): Promise<string>; | ||
genericRequest(data: object, action: string): Promise<string>; | ||
supportsSubscriptions(): boolean; | ||
@@ -67,0 +68,0 @@ subscribe(): void; |
@@ -51,3 +51,3 @@ "use strict"; | ||
this.scanQRCode = this.scanQRCode.bind(this); | ||
this.arbitraryRequest = this.arbitraryRequest.bind(this); | ||
this.genericRequest = this.genericRequest.bind(this); | ||
this._jsonRpcUrlFromOpts = options.jsonRpcUrl; | ||
@@ -157,3 +157,22 @@ this._overrideIsMetaMask = options.overrideIsMetaMask; | ||
} | ||
async switchEthereumChain(rpcUrl, chainId) { | ||
async addEthereumChain(chainId, rpcUrls, blockExplorerUrls, chainName, iconUrls, nativeCurrency) { | ||
var _a, _b; | ||
const relay = await this.initializeRelay(); | ||
const res = await relay.addEthereumChain(chainId.toString(), rpcUrls, blockExplorerUrls, chainName, iconUrls, nativeCurrency).promise; | ||
if (typeof res.result === 'boolean') { | ||
// legacy handling. to be deprecated in february 2022 | ||
if (res.result === true) { | ||
this._storage.setItem(HAS_CHAIN_BEEN_SWITCHED_KEY, "true"); | ||
this.updateProviderInfo(rpcUrls[0], chainId, false); | ||
} | ||
return res.result === true; | ||
} | ||
if (((_a = res.result) === null || _a === void 0 ? void 0 : _a.isApproved) === true) { | ||
this._storage.setItem(HAS_CHAIN_BEEN_SWITCHED_KEY, "true"); | ||
this.updateProviderInfo(rpcUrls[0], chainId, false); | ||
} | ||
return ((_b = res.result) === null || _b === void 0 ? void 0 : _b.isApproved) === true; | ||
} | ||
async switchEthereumChain(chainId) { | ||
var _a; | ||
if ((0, util_1.ensureIntNumber)(chainId) === this.getChainId()) { | ||
@@ -164,6 +183,18 @@ return; | ||
const res = await relay.switchEthereumChain(chainId.toString(10)).promise; | ||
if (res.result === true) { | ||
this._storage.setItem(HAS_CHAIN_BEEN_SWITCHED_KEY, "true"); | ||
this.updateProviderInfo(rpcUrl, chainId, false); | ||
if (typeof res.result !== 'boolean') { | ||
const switchResponse = res.result; | ||
if (switchResponse.isApproved && switchResponse.rpcUrl.length > 0) { | ||
this._storage.setItem(HAS_CHAIN_BEEN_SWITCHED_KEY, "true"); | ||
this.updateProviderInfo(switchResponse.rpcUrl, chainId, false); | ||
} | ||
} | ||
else { | ||
// this is for legacy clients that return a boolean as result. can deprecate below in February 2022 | ||
if (res.result) { | ||
this._storage.setItem(HAS_CHAIN_BEEN_SWITCHED_KEY, "true"); | ||
const ethereumChain = EthereumChain_1.EthereumChain.fromChainId(BigInt(chainId)); | ||
const rpcUrl = (_a = EthereumChain_1.EthereumChain.rpcUrl(ethereumChain)) !== null && _a !== void 0 ? _a : ""; | ||
this.updateProviderInfo(rpcUrl, chainId, false); | ||
} | ||
} | ||
} | ||
@@ -278,5 +309,5 @@ setAppInfo(appName, appLogoUrl) { | ||
} | ||
async arbitraryRequest(data) { | ||
async genericRequest(data, action) { | ||
const relay = await this.initializeRelay(); | ||
const res = await relay.arbitraryRequest(data).promise; | ||
const res = await relay.genericRequest(data, action).promise; | ||
if (typeof res.result !== "string") { | ||
@@ -675,31 +706,31 @@ throw new Error("result was not a string"); | ||
async _walletlink_arbitrary(params) { | ||
const data = params[0]; | ||
const action = params[0]; | ||
const data = params[1]; | ||
if (typeof data !== "string") { | ||
throw new Error("parameter must be a string"); | ||
} | ||
const result = await this.arbitraryRequest(data); | ||
if (typeof action !== "object" || action === null) { | ||
throw new Error("parameter must be an object"); | ||
} | ||
const result = await this.genericRequest(action, data); | ||
return { jsonrpc: "2.0", id: 0, result }; | ||
} | ||
async _wallet_addEthereumChain(params) { | ||
var _a, _b; | ||
const request = (params[0]); | ||
if (((_a = request.rpcUrls) === null || _a === void 0 ? void 0 : _a.length) === 0) { | ||
return { jsonrpc: '2.0', id: 0, error: { code: 2, message: `please pass in at least 1 rpcUrl` } }; | ||
} | ||
const chainIdNumber = parseInt(request.chainId, 16); | ||
const ethereumChain = EthereumChain_1.EthereumChain.fromChainId(BigInt(chainIdNumber)); | ||
if (ethereumChain === undefined) { | ||
return { jsonrpc: '2.0', id: 0, error: { code: 2, message: `chainId ${request.chainId} not supported` } }; | ||
const success = await this.addEthereumChain(chainIdNumber, (_b = request.rpcUrls) !== null && _b !== void 0 ? _b : [], request.blockExplorerUrls, request.chainName, request.iconUrls, request.nativeCurrency); | ||
if (success) { | ||
return { jsonrpc: '2.0', id: 0, result: null }; | ||
} | ||
const rpcUrl = EthereumChain_1.EthereumChain.rpcUrl(ethereumChain); | ||
// @ts-ignore | ||
await this.switchEthereumChain(rpcUrl, parseInt(request.chainId, 16)); | ||
return { jsonrpc: '2.0', id: 0, result: null }; | ||
else { | ||
return { jsonrpc: '2.0', id: 0, error: { code: 2, message: `unable to add ethereum chain` } }; | ||
} | ||
} | ||
async _wallet_switchEthereumChain(params) { | ||
const request = (params[0]); | ||
const chainIdNumber = parseInt(request.chainId, 16); | ||
const ethereumChain = EthereumChain_1.EthereumChain.fromChainId(BigInt(chainIdNumber)); | ||
if (ethereumChain === undefined) { | ||
return { jsonrpc: '2.0', id: 0, error: { code: 2, message: `chainId ${request.chainId} not supported` } }; | ||
} | ||
const rpcUrl = EthereumChain_1.EthereumChain.rpcUrl(ethereumChain); | ||
// @ts-ignore | ||
await this.switchEthereumChain(rpcUrl, parseInt(request.chainId, 16)); | ||
await this.switchEthereumChain(parseInt(request.chainId, 16)); | ||
return { jsonrpc: "2.0", id: 0, result: null }; | ||
@@ -706,0 +737,0 @@ } |
@@ -27,3 +27,3 @@ import { Observable } from "rxjs"; | ||
onCancel: () => void; | ||
onApprove: () => void; | ||
onApprove: (rpcUrl: string) => void; | ||
chainId: string; | ||
@@ -30,0 +30,0 @@ }): void; |
@@ -12,4 +12,4 @@ /// <reference types="node" /> | ||
import { WalletLinkRelayEventManager } from "./WalletLinkRelayEventManager"; | ||
import { Web3Request } from "./Web3Request"; | ||
import { AddEthereumChainResponse, ArbitraryResponse, EthereumAddressFromSignedMessageResponse, RequestEthereumAccountsResponse, ScanQRCodeResponse, SignEthereumMessageResponse, SignEthereumTransactionResponse, SubmitEthereumTransactionResponse, SwitchEthereumChainResponse, Web3Response } from "./Web3Response"; | ||
import { GenericRequest, Web3Request } from "./Web3Request"; | ||
import { AddEthereumChainResponse, EthereumAddressFromSignedMessageResponse, GenericResponse, RequestEthereumAccountsResponse, ScanQRCodeResponse, SignEthereumMessageResponse, SignEthereumTransactionResponse, SubmitEthereumTransactionResponse, SwitchEthereumChainResponse, Web3Response } from "./Web3Response"; | ||
export interface WalletLinkRelayOptions { | ||
@@ -53,4 +53,4 @@ walletLinkUrl: string; | ||
scanQRCode(regExp: RegExpString): CancelablePromise<ScanQRCodeResponse>; | ||
arbitraryRequest(data: string): CancelablePromise<ArbitraryResponse>; | ||
addEthereumChain(chainId: string, blockExplorerUrls?: string[], chainName?: string, iconUrls?: string[], nativeCurrency?: { | ||
genericRequest(data: object, action: string): CancelablePromise<GenericResponse>; | ||
addEthereumChain(chainId: string, rpcUrls: string[], blockExplorerUrls?: string[], chainName?: string, iconUrls?: string[], nativeCurrency?: { | ||
name: string; | ||
@@ -60,2 +60,3 @@ symbol: string; | ||
}): CancelablePromise<AddEthereumChainResponse>; | ||
sendGenericMessage(request: GenericRequest): CancelablePromise<GenericResponse>; | ||
sendRequest<T extends Web3Request, U extends Web3Response>(request: T): CancelablePromise<U>; | ||
@@ -62,0 +63,0 @@ setConnectDisabled(disabled: boolean): void; |
@@ -104,7 +104,27 @@ "use strict"; | ||
var _a; | ||
(_a = this.walletLinkAnalytics) === null || _a === void 0 ? void 0 : _a.sendEvent(init_1.EVENTS.GENERAL_ERROR, { message: 'Had error decrypting', value: 'username' }); | ||
(_a = this.walletLinkAnalytics) === null || _a === void 0 ? void 0 : _a.sendEvent(init_1.EVENTS.GENERAL_ERROR, { | ||
message: "Had error decrypting", | ||
value: "username" | ||
}); | ||
} | ||
})); | ||
this.subscriptions.add(this.connection.sessionConfig$ | ||
.pipe((0, operators_1.filter)(c => c.metadata && c.metadata.ChainId !== undefined && c.metadata.JsonRpcUrl !== undefined)) | ||
.pipe((0, operators_1.filter)(c => c.metadata && c.metadata.AppVersion !== undefined)) | ||
.pipe((0, operators_1.mergeMap)(c => aes256gcm.decrypt(c.metadata.AppVersion, this._session.secret))) | ||
.subscribe({ | ||
next: appVersion => { | ||
this.storage.setItem(WalletLinkRelayAbstract_1.APP_VERSION_KEY, appVersion); | ||
}, | ||
error: () => { | ||
var _a; | ||
(_a = this.walletLinkAnalytics) === null || _a === void 0 ? void 0 : _a.sendEvent(init_1.EVENTS.GENERAL_ERROR, { | ||
message: "Had error decrypting", | ||
value: "appversion" | ||
}); | ||
} | ||
})); | ||
this.subscriptions.add(this.connection.sessionConfig$ | ||
.pipe((0, operators_1.filter)(c => c.metadata && | ||
c.metadata.ChainId !== undefined && | ||
c.metadata.JsonRpcUrl !== undefined)) | ||
.pipe((0, operators_1.mergeMap)(c => (0, rxjs_1.zip)(aes256gcm.decrypt(c.metadata.ChainId, this._session.secret), aes256gcm.decrypt(c.metadata.JsonRpcUrl, this._session.secret)))) | ||
@@ -120,3 +140,6 @@ .pipe((0, operators_1.distinctUntilChanged)()) | ||
var _a; | ||
(_a = this.walletLinkAnalytics) === null || _a === void 0 ? void 0 : _a.sendEvent(init_1.EVENTS.GENERAL_ERROR, { message: 'Had error decrypting', value: 'chainId|jsonRpcUrl' }); | ||
(_a = this.walletLinkAnalytics) === null || _a === void 0 ? void 0 : _a.sendEvent(init_1.EVENTS.GENERAL_ERROR, { | ||
message: "Had error decrypting", | ||
value: "chainId|jsonRpcUrl" | ||
}); | ||
} | ||
@@ -150,3 +173,6 @@ })); | ||
var _a; | ||
(_a = this.walletLinkAnalytics) === null || _a === void 0 ? void 0 : _a.sendEvent(init_1.EVENTS.GENERAL_ERROR, { message: 'Had error decrypting', value: 'selectedAddress' }); | ||
(_a = this.walletLinkAnalytics) === null || _a === void 0 ? void 0 : _a.sendEvent(init_1.EVENTS.GENERAL_ERROR, { | ||
message: "Had error decrypting", | ||
value: "selectedAddress" | ||
}); | ||
} | ||
@@ -303,9 +329,12 @@ })); | ||
} | ||
arbitraryRequest(data) { | ||
genericRequest(data, action) { | ||
return this.sendRequest({ | ||
method: Web3Method_1.Web3Method.arbitrary, | ||
params: { data } | ||
method: Web3Method_1.Web3Method.generic, | ||
params: { | ||
action, | ||
data | ||
} | ||
}); | ||
} | ||
addEthereumChain(chainId, blockExplorerUrls, chainName, iconUrls, nativeCurrency) { | ||
addEthereumChain(chainId, rpcUrls, blockExplorerUrls, chainName, iconUrls, nativeCurrency) { | ||
return this.sendRequest({ | ||
@@ -315,2 +344,3 @@ method: Web3Method_1.Web3Method.addEthereumChain, | ||
chainId, | ||
rpcUrls, | ||
blockExplorerUrls, | ||
@@ -323,2 +353,5 @@ chainName, | ||
} | ||
sendGenericMessage(request) { | ||
return this.sendRequest(request); | ||
} | ||
sendRequest(request) { | ||
@@ -370,9 +403,9 @@ let hideSnackbarItem = null; | ||
id, | ||
response: (0, Web3Response_1.SwitchEthereumChainResponse)(false) | ||
response: (0, Web3Response_1.SwitchEthereumChainResponse)({ isApproved: false, rpcUrl: "" }) | ||
})); | ||
}; | ||
const approve = () => { | ||
const approve = (rpcUrl) => { | ||
this.handleWeb3ResponseMessage((0, Web3ResponseMessage_1.Web3ResponseMessage)({ | ||
id, | ||
response: (0, Web3Response_1.SwitchEthereumChainResponse)(true) | ||
response: (0, Web3Response_1.SwitchEthereumChainResponse)({ isApproved: false, rpcUrl }) | ||
})); | ||
@@ -516,3 +549,6 @@ }; | ||
var _a; | ||
(_a = this.walletLinkAnalytics) === null || _a === void 0 ? void 0 : _a.sendEvent(init_1.EVENTS.GENERAL_ERROR, { message: 'Had error decrypting', value: 'incomingEvent' }); | ||
(_a = this.walletLinkAnalytics) === null || _a === void 0 ? void 0 : _a.sendEvent(init_1.EVENTS.GENERAL_ERROR, { | ||
message: "Had error decrypting", | ||
value: "incomingEvent" | ||
}); | ||
} | ||
@@ -519,0 +555,0 @@ })); |
@@ -6,5 +6,6 @@ /// <reference types="node" /> | ||
import { Web3Request } from "./Web3Request"; | ||
import { AddEthereumChainResponse, ArbitraryResponse, EthereumAddressFromSignedMessageResponse, RequestEthereumAccountsResponse, ScanQRCodeResponse, SignEthereumMessageResponse, SignEthereumTransactionResponse, SubmitEthereumTransactionResponse, SwitchEthereumChainResponse, Web3Response } from './Web3Response'; | ||
import { AddEthereumChainResponse, EthereumAddressFromSignedMessageResponse, GenericResponse, RequestEthereumAccountsResponse, ScanQRCodeResponse, SignEthereumMessageResponse, SignEthereumTransactionResponse, SubmitEthereumTransactionResponse, SwitchEthereumChainResponse, Web3Response } from "./Web3Response"; | ||
export declare const WALLET_USER_NAME_KEY = "walletUsername"; | ||
export declare const LOCAL_STORAGE_ADDRESSES_KEY = "Addresses"; | ||
export declare const APP_VERSION_KEY = "AppVersion"; | ||
export declare type CancelablePromise<T> = { | ||
@@ -17,3 +18,3 @@ promise: Promise<T>; | ||
abstract requestEthereumAccounts(): CancelablePromise<RequestEthereumAccountsResponse>; | ||
abstract addEthereumChain(chainId: string, blockExplorerUrls?: string[], chainName?: string, iconUrls?: string[], nativeCurrency?: { | ||
abstract addEthereumChain(chainId: string, rpcUrls: string[], blockExplorerUrls?: string[], chainName?: string, iconUrls?: string[], nativeCurrency?: { | ||
name: string; | ||
@@ -30,3 +31,3 @@ symbol: string; | ||
abstract scanQRCode(regExp: RegExpString): CancelablePromise<ScanQRCodeResponse>; | ||
abstract arbitraryRequest(data: string): CancelablePromise<ArbitraryResponse>; | ||
abstract genericRequest(data: object, action: string): CancelablePromise<GenericResponse>; | ||
abstract sendRequest<T extends Web3Request, U extends Web3Response>(request: T): CancelablePromise<U>; | ||
@@ -33,0 +34,0 @@ abstract setAppInfo(appName: string, appLogoUrl: string | null): void; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.WalletLinkRelayAbstract = exports.LOCAL_STORAGE_ADDRESSES_KEY = exports.WALLET_USER_NAME_KEY = void 0; | ||
exports.WalletLinkRelayAbstract = exports.APP_VERSION_KEY = exports.LOCAL_STORAGE_ADDRESSES_KEY = exports.WALLET_USER_NAME_KEY = void 0; | ||
exports.WALLET_USER_NAME_KEY = "walletUsername"; | ||
exports.LOCAL_STORAGE_ADDRESSES_KEY = "Addresses"; | ||
exports.APP_VERSION_KEY = "AppVersion"; | ||
class WalletLinkRelayAbstract { | ||
} | ||
exports.WalletLinkRelayAbstract = WalletLinkRelayAbstract; |
@@ -8,3 +8,3 @@ export declare enum Web3Method { | ||
scanQRCode = "scanQRCode", | ||
arbitrary = "arbitrary", | ||
generic = "generic", | ||
childRequestEthereumAccounts = "childRequestEthereumAccounts", | ||
@@ -11,0 +11,0 @@ addEthereumChain = "addEthereumChain", |
@@ -15,3 +15,3 @@ "use strict"; | ||
Web3Method["scanQRCode"] = "scanQRCode"; | ||
Web3Method["arbitrary"] = "arbitrary"; | ||
Web3Method["generic"] = "generic"; | ||
Web3Method["childRequestEthereumAccounts"] = "childRequestEthereumAccounts"; | ||
@@ -18,0 +18,0 @@ Web3Method["addEthereumChain"] = "addEthereumChain"; |
@@ -57,6 +57,7 @@ import { AddressString, BigIntString, HexString, IntNumber, RegExpString } from "../types"; | ||
}>; | ||
export declare type ArbitraryRequest = BaseWeb3Request<Web3Method.arbitrary, { | ||
data: string; | ||
export declare type GenericRequest = BaseWeb3Request<Web3Method.generic, { | ||
action: string; | ||
data: object; | ||
}>; | ||
export declare type Web3Request = RequestEthereumAccountsRequest | SignEthereumMessageRequest | SignEthereumTransactionRequest | SubmitEthereumTransactionRequest | EthereumAddressFromSignedMessageRequest | ScanQRCodeRequest | ArbitraryRequest | AddEthereumChainRequest | SwitchEthereumChainRequest; | ||
export declare type Web3Request = RequestEthereumAccountsRequest | SignEthereumMessageRequest | SignEthereumTransactionRequest | SubmitEthereumTransactionRequest | EthereumAddressFromSignedMessageRequest | ScanQRCodeRequest | GenericRequest | AddEthereumChainRequest | SwitchEthereumChainRequest; | ||
export {}; |
@@ -13,5 +13,9 @@ import { AddressString, HexString } from "../types"; | ||
export declare type RequestEthereumAccountsResponse = BaseWeb3Response<AddressString[]>; | ||
export declare type AddEthereumChainResponse = BaseWeb3Response<null>; | ||
export declare type SwitchEthereumChainResponse = BaseWeb3Response<boolean>; | ||
export declare function SwitchEthereumChainResponse(isApproved: boolean): SwitchEthereumChainResponse; | ||
export declare type AddEthereumChainResponse = BaseWeb3Response<SwitchResponse | boolean>; | ||
export declare type SwitchEthereumChainResponse = BaseWeb3Response<SwitchResponse | boolean>; | ||
export declare type SwitchResponse = { | ||
isApproved: boolean; | ||
rpcUrl: string; | ||
}; | ||
export declare function SwitchEthereumChainResponse(switchResponse: SwitchResponse): SwitchEthereumChainResponse; | ||
export declare function RequestEthereumAccountsResponse(addresses: AddressString[]): RequestEthereumAccountsResponse; | ||
@@ -28,4 +32,4 @@ export declare function isRequestEthereumAccountsResponse(res: any): res is RequestEthereumAccountsResponse; | ||
export declare type ScanQRCodeResponse = BaseWeb3Response<string>; | ||
export declare type ArbitraryResponse = BaseWeb3Response<string>; | ||
export declare type Web3Response = ErrorResponse | RequestEthereumAccountsResponse | SignEthereumMessageResponse | SignEthereumTransactionResponse | SubmitEthereumTransactionResponse | EthereumAddressFromSignedMessageResponse | ScanQRCodeResponse | ArbitraryResponse | AddEthereumChainResponse | SwitchEthereumChainResponse; | ||
export declare type GenericResponse = BaseWeb3Response<object>; | ||
export declare type Web3Response = ErrorResponse | RequestEthereumAccountsResponse | SignEthereumMessageResponse | SignEthereumTransactionResponse | SubmitEthereumTransactionResponse | EthereumAddressFromSignedMessageResponse | ScanQRCodeResponse | GenericResponse | AddEthereumChainResponse | SwitchEthereumChainResponse; | ||
export {}; |
@@ -12,4 +12,7 @@ "use strict"; | ||
exports.ErrorResponse = ErrorResponse; | ||
function SwitchEthereumChainResponse(isApproved) { | ||
return { method: Web3Method_1.Web3Method.switchEthereumChain, result: isApproved }; | ||
function SwitchEthereumChainResponse(switchResponse) { | ||
return { | ||
method: Web3Method_1.Web3Method.switchEthereumChain, | ||
result: switchResponse | ||
}; | ||
} | ||
@@ -16,0 +19,0 @@ exports.SwitchEthereumChainResponse = SwitchEthereumChainResponse; |
{ | ||
"name": "walletlink", | ||
"version": "2.2.10", | ||
"version": "2.2.11", | ||
"description": "WalletLink 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
334662
6588