Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@coinbase/wallet-sdk

Package Overview
Dependencies
Maintainers
13
Versions
79
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@coinbase/wallet-sdk - npm Package Compare versions

Comparing version 3.9.2 to 4.0.0-beta.0

dist/CoinbaseWalletProvider.d.ts

70

dist/CoinbaseWalletSDK.d.ts
import { LogoType } from './assets/wallet-logo';
import { CoinbaseWalletProvider } from './provider/CoinbaseWalletProvider';
import { DiagnosticLogger } from './provider/DiagnosticLogger';
import { RelayUI, RelayUIOptions } from './relay/RelayUI';
import { ProviderInterface } from './core/type/ProviderInterface';
import { ConnectionPreference } from './core/communicator/ConnectionPreference';
/** Coinbase Wallet SDK Constructor Options */

@@ -10,36 +9,13 @@ export interface CoinbaseWalletSDKOptions {

/** @optional Application logo image URL; favicon is used if unspecified */
appLogoUrl?: string | null;
/** @optional Use dark theme */
darkMode?: boolean;
/** @optional Coinbase Wallet link server URL; for most, leave it unspecified */
linkAPIUrl?: string;
/** @optional an implementation of WalletUI; for most, leave it unspecified */
uiConstructor?: (options: Readonly<RelayUIOptions>) => RelayUI;
/** @optional a diagnostic tool for debugging; for most, leave it unspecified */
diagnosticLogger?: DiagnosticLogger;
/** @optional whether wallet link provider should override the isMetaMask property. */
overrideIsMetaMask?: boolean;
/** @optional whether wallet link provider should override the isCoinbaseWallet property. */
overrideIsCoinbaseWallet?: boolean;
/** @optional whether coinbase wallet provider should override the isCoinbaseBrowser property. */
overrideIsCoinbaseBrowser?: boolean;
/** @optional whether or not onboarding overlay popup should be displayed */
headlessMode?: boolean;
/** @optional whether or not to reload dapp automatically after disconnect, defaults to true */
reloadOnDisconnect?: boolean;
/** @optional whether to connect mobile web app via WalletLink, defaults to false */
enableMobileWalletLink?: boolean;
appLogoUrl?: string;
/** @optional Array of chainIds your dapp supports */
chainIds?: string[];
/** @optional Pre-select the wallet connection method */
connectionPreference?: ConnectionPreference;
}
export declare class CoinbaseWalletSDK {
static VERSION: string;
private _appName;
private _appLogoUrl;
private _relay;
private _relayEventManager;
private _storage;
private _overrideIsMetaMask;
private _overrideIsCoinbaseWallet;
private _overrideIsCoinbaseBrowser;
private _diagnosticLogger?;
private _reloadOnDisconnect?;
private appName;
private appLogoUrl;
private connectionPreference;
private chainIds;
/**

@@ -50,25 +26,6 @@ * Constructor

constructor(options: Readonly<CoinbaseWalletSDKOptions>);
/**
* Create a Web3 Provider object
* @param jsonRpcUrl Ethereum JSON RPC URL (Default: "")
* @param chainId Ethereum Chain ID (Default: 1)
* @returns A Web3 Provider
*/
makeWeb3Provider(jsonRpcUrl?: string, chainId?: number): CoinbaseWalletProvider;
/**
* Set application information
* @param appName Application name
* @param appLogoUrl Application logo image URL
*/
setAppInfo(appName: string | undefined, appLogoUrl: string | null | undefined): void;
/**
* Disconnect. After disconnecting, this will reload the web page to ensure
* all potential stale state is cleared.
*/
private storeLatestVersion;
makeWeb3Provider(): ProviderInterface;
disconnect(): void;
/**
* Return QR URL for mobile wallet connection, will return null if extension is installed
*/
getQrUrl(): string | null;
/**
* Official Coinbase Wallet logo for developers to use on their frontend

@@ -82,3 +39,2 @@ * @param type Type of wallet logo: "standard" | "circle" | "text" | "textWithLogo" | "textLight" | "textWithLogoLight"

private get coinbaseBrowser();
private isCipherProvider;
}
"use strict";
// Copyright (c) 2018-2023 Coinbase, Inc. <https://www.coinbase.com/>
// Licensed under the Apache License, version 2.0
// Copyright (c) 2018-2024 Coinbase, Inc. <https://www.coinbase.com/>
Object.defineProperty(exports, "__esModule", { value: true });
exports.CoinbaseWalletSDK = void 0;
const wallet_logo_1 = require("./assets/wallet-logo");
const constants_1 = require("./core/constants");
const CoinbaseWalletProvider_1 = require("./CoinbaseWalletProvider");
const ScopedLocalStorage_1 = require("./core/storage/ScopedLocalStorage");
const util_1 = require("./core/util");
const ScopedLocalStorage_1 = require("./lib/ScopedLocalStorage");
const CoinbaseWalletProvider_1 = require("./provider/CoinbaseWalletProvider");
const MobileRelay_1 = require("./relay/mobile/MobileRelay");
const MobileRelayUI_1 = require("./relay/mobile/MobileRelayUI");
const RelayEventManager_1 = require("./relay/RelayEventManager");
const WalletLinkRelayUI_1 = require("./relay/walletlink/ui/WalletLinkRelayUI");
const WalletLinkRelay_1 = require("./relay/walletlink/WalletLinkRelay");
const version_1 = require("./version");

@@ -23,62 +16,20 @@ class CoinbaseWalletSDK {

constructor(options) {
var _a, _b, _c;
this._appName = '';
this._appLogoUrl = null;
this._relay = null;
this._relayEventManager = null;
const linkAPIUrl = options.linkAPIUrl || constants_1.LINK_API_URL;
if (typeof options.overrideIsMetaMask === 'undefined') {
this._overrideIsMetaMask = false;
}
else {
this._overrideIsMetaMask = options.overrideIsMetaMask;
}
this._overrideIsCoinbaseWallet = (_a = options.overrideIsCoinbaseWallet) !== null && _a !== void 0 ? _a : true;
this._overrideIsCoinbaseBrowser = (_b = options.overrideIsCoinbaseBrowser) !== null && _b !== void 0 ? _b : false;
this._diagnosticLogger = options.diagnosticLogger;
this._reloadOnDisconnect = (_c = options.reloadOnDisconnect) !== null && _c !== void 0 ? _c : true;
const url = new URL(linkAPIUrl);
const origin = `${url.protocol}//${url.host}`;
this._storage = new ScopedLocalStorage_1.ScopedLocalStorage(`-walletlink:${origin}`); // needs migration to preserve local states
this._storage.setItem('version', CoinbaseWalletSDK.VERSION);
if (this.walletExtension || this.coinbaseBrowser) {
return;
}
this._relayEventManager = new RelayEventManager_1.RelayEventManager();
const isMobile = (0, util_1.isMobileWeb)();
const uiConstructor = options.uiConstructor ||
((opts) => (isMobile ? new MobileRelayUI_1.MobileRelayUI(opts) : new WalletLinkRelayUI_1.WalletLinkRelayUI(opts)));
const relayOption = {
linkAPIUrl,
version: version_1.LIB_VERSION,
darkMode: !!options.darkMode,
uiConstructor,
storage: this._storage,
relayEventManager: this._relayEventManager,
diagnosticLogger: this._diagnosticLogger,
reloadOnDisconnect: this._reloadOnDisconnect,
enableMobileWalletLink: options.enableMobileWalletLink,
};
this._relay = isMobile ? new MobileRelay_1.MobileRelay(relayOption) : new WalletLinkRelay_1.WalletLinkRelay(relayOption);
this.setAppInfo(options.appName, options.appLogoUrl);
if (options.headlessMode)
return;
this._relay.attachUI();
this.connectionPreference = options.connectionPreference || 'default';
this.chainIds = options.chainIds ? options.chainIds.map(Number) : [];
this.appName = options.appName || 'DApp';
this.appLogoUrl = options.appLogoUrl || (0, util_1.getFavicon)();
this.storeLatestVersion();
}
/**
* Create a Web3 Provider object
* @param jsonRpcUrl Ethereum JSON RPC URL (Default: "")
* @param chainId Ethereum Chain ID (Default: 1)
* @returns A Web3 Provider
*/
makeWeb3Provider(jsonRpcUrl = '', chainId = 1) {
const extension = this.walletExtension;
if (extension) {
if (!this.isCipherProvider(extension)) {
extension.setProviderInfo(jsonRpcUrl, chainId);
storeLatestVersion() {
const versionStorage = new ScopedLocalStorage_1.ScopedLocalStorage('CBWSDK');
versionStorage.setItem('VERSION', version_1.LIB_VERSION);
}
makeWeb3Provider() {
var _a;
if (this.connectionPreference !== 'embedded') {
const extension = this.walletExtension;
if (extension) {
(_a = extension.setAppInfo) === null || _a === void 0 ? void 0 : _a.call(extension, this.appName, this.appLogoUrl);
return extension;
}
if (this._reloadOnDisconnect === false &&
typeof extension.disableReloadOnDisconnect === 'function')
extension.disableReloadOnDisconnect();
return extension;
}

@@ -89,44 +40,9 @@ const dappBrowser = this.coinbaseBrowser;

}
const relay = this._relay;
if (!relay || !this._relayEventManager || !this._storage) {
throw new Error('Relay not initialized, should never happen');
}
if (!jsonRpcUrl)
relay.setConnectDisabled(true);
return new CoinbaseWalletProvider_1.CoinbaseWalletProvider({
relayProvider: () => Promise.resolve(relay),
relayEventManager: this._relayEventManager,
storage: this._storage,
jsonRpcUrl,
chainId,
qrUrl: this.getQrUrl(),
diagnosticLogger: this._diagnosticLogger,
overrideIsMetaMask: this._overrideIsMetaMask,
overrideIsCoinbaseWallet: this._overrideIsCoinbaseWallet,
overrideIsCoinbaseBrowser: this._overrideIsCoinbaseBrowser,
appName: this.appName,
appLogoUrl: this.appLogoUrl,
appChainIds: this.chainIds,
connectionPreference: this.connectionPreference,
});
}
/**
* Set application information
* @param appName Application name
* @param appLogoUrl Application logo image URL
*/
setAppInfo(appName, appLogoUrl) {
var _a;
this._appName = appName || 'DApp';
this._appLogoUrl = appLogoUrl || (0, util_1.getFavicon)();
const extension = this.walletExtension;
if (extension) {
if (!this.isCipherProvider(extension)) {
extension.setAppInfo(this._appName, this._appLogoUrl);
}
}
else {
(_a = this._relay) === null || _a === void 0 ? void 0 : _a.setAppInfo(this._appName, this._appLogoUrl);
}
}
/**
* Disconnect. After disconnecting, this will reload the web page to ensure
* all potential stale state is cleared.
*/
disconnect() {

@@ -136,16 +52,9 @@ var _a;

if (extension) {
void extension.close();
(_a = extension.close) === null || _a === void 0 ? void 0 : _a.call(extension);
}
else {
(_a = this._relay) === null || _a === void 0 ? void 0 : _a.resetAndReload();
ScopedLocalStorage_1.ScopedLocalStorage.clearAll();
}
}
/**
* Return QR URL for mobile wallet connection, will return null if extension is installed
*/
getQrUrl() {
var _a, _b;
return (_b = (_a = this._relay) === null || _a === void 0 ? void 0 : _a.getQRCodeUrl()) !== null && _b !== void 0 ? _b : null;
}
/**
* Official Coinbase Wallet logo for developers to use on their frontend

@@ -160,4 +69,3 @@ * @param type Type of wallet logo: "standard" | "circle" | "text" | "textWithLogo" | "textLight" | "textWithLogoLight"

get walletExtension() {
var _a;
return (_a = window.coinbaseWalletExtension) !== null && _a !== void 0 ? _a : window.walletLinkExtension;
return window.coinbaseWalletExtension;
}

@@ -181,8 +89,3 @@ get coinbaseBrowser() {

}
isCipherProvider(provider) {
// @ts-expect-error isCipher walletlink property
return typeof provider.isCipher === 'boolean' && provider.isCipher;
}
}
exports.CoinbaseWalletSDK = CoinbaseWalletSDK;
CoinbaseWalletSDK.VERSION = version_1.LIB_VERSION;

@@ -1,1 +0,3 @@

export declare const LINK_API_URL = "https://www.walletlink.org";
export declare const CB_KEYS_URL = "https://keys.coinbase.com/connect";
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.LINK_API_URL = void 0;
exports.LINK_API_URL = 'https://www.walletlink.org';
exports.CBW_MOBILE_DEEPLINK_URL = exports.WALLETLINK_URL = exports.CB_KEYS_URL = void 0;
exports.CB_KEYS_URL = 'https://keys.coinbase.com/connect';
exports.WALLETLINK_URL = 'https://www.walletlink.org';
exports.CBW_MOBILE_DEEPLINK_URL = 'https://go.cb-w.com/walletlink';

@@ -5,3 +5,2 @@ "use strict";

const constants_1 = require("./constants");
const utils_1 = require("./utils");
exports.standardErrors = {

@@ -63,9 +62,27 @@ rpc: {

// Internal
function isJsonRpcServerError(code) {
return code >= -32099 && code <= -32000;
}
function hasKey(obj, key) {
return Object.prototype.hasOwnProperty.call(obj, key);
}
function getMessageFromCode(code) {
if (code && Number.isInteger(code)) {
const codeString = code.toString();
if (hasKey(constants_1.errorValues, codeString)) {
return constants_1.errorValues[codeString].message;
}
if (isJsonRpcServerError(code)) {
return 'Unspecified server error.';
}
}
return 'Unspecified error message.';
}
function getEthJsonRpcError(code, arg) {
const [message, data] = parseOpts(arg);
return new EthereumRpcError(code, message || (0, utils_1.getMessageFromCode)(code), data);
return new EthereumRpcError(code, message || getMessageFromCode(code), data);
}
function getEthProviderError(code, arg) {
const [message, data] = parseOpts(arg);
return new EthereumProviderError(code, message || (0, utils_1.getMessageFromCode)(code), data);
return new EthereumProviderError(code, message || getMessageFromCode(code), data);
}

@@ -72,0 +89,0 @@ function parseOpts(arg) {

@@ -1,7 +0,3 @@

import { standardErrorCodes } from './constants';
import { standardErrors } from './errors';
import { SerializedError, serializeError } from './serialize';
import { getErrorCode, getMessageFromCode } from './utils';
export { getErrorCode, getMessageFromCode, serializeError, standardErrorCodes, standardErrors };
export type ErrorType = Error | SerializedError;
export type ErrorHandler = (error?: ErrorType) => void;
export { standardErrorCodes } from './constants';
export { standardErrors } from './errors';
export type { SerializedEthereumRpcError } from './type';
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.standardErrors = exports.standardErrorCodes = exports.serializeError = exports.getMessageFromCode = exports.getErrorCode = void 0;
const constants_1 = require("./constants");
exports.standardErrors = exports.standardErrorCodes = void 0;
var constants_1 = require("./constants");
Object.defineProperty(exports, "standardErrorCodes", { enumerable: true, get: function () { return constants_1.standardErrorCodes; } });
const errors_1 = require("./errors");
var errors_1 = require("./errors");
Object.defineProperty(exports, "standardErrors", { enumerable: true, get: function () { return errors_1.standardErrors; } });
const serialize_1 = require("./serialize");
Object.defineProperty(exports, "serializeError", { enumerable: true, get: function () { return serialize_1.serializeError; } });
const utils_1 = require("./utils");
Object.defineProperty(exports, "getErrorCode", { enumerable: true, get: function () { return utils_1.getErrorCode; } });
Object.defineProperty(exports, "getMessageFromCode", { enumerable: true, get: function () { return utils_1.getMessageFromCode; } });
/// <reference types="node" />
import BN from 'bn.js';
import { AddressString, BigIntString, HexString, IntNumber, RegExpString } from './type';

@@ -11,3 +10,3 @@ /**

export declare function hexStringFromBuffer(buf: Buffer, includePrefix?: boolean): HexString;
export declare function bigIntStringFromBN(bn: BN): BigIntString;
export declare function bigIntStringFromBigInt(bi: bigint): BigIntString;
export declare function intNumberFromHexString(hex: HexString): IntNumber;

@@ -25,3 +24,3 @@ export declare function hexStringFromIntNumber(num: IntNumber): HexString;

export declare function ensureRegExpString(regExp: unknown): RegExpString;
export declare function ensureBN(val: unknown): BN;
export declare function ensureBigInt(val: unknown): bigint;
export declare function ensureParsedJSONObject<T extends object>(val: unknown): T;

@@ -31,5 +30,3 @@ export declare function isBigNumber(val: unknown): boolean;

export declare function getFavicon(): string | null;
export declare function createQrUrl(sessionId: string, sessionSecret: string, serverUrl: string, isParentConnection: boolean, version: string, chainId: number): string;
export declare function isInIFrame(): boolean;
export declare function getLocation(): Location;
export declare function isMobileWeb(): boolean;
export declare function areAddressArraysEqual(arr1: AddressString[], arr2: AddressString[]): boolean;
export declare function showDeprecationWarning(oldMethod: string, instructions: string): void;
"use strict";
// Copyright (c) 2018-2023 Coinbase, Inc. <https://www.coinbase.com/>
// Licensed under the Apache License, version 2.0
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.isMobileWeb = exports.getLocation = exports.isInIFrame = exports.createQrUrl = exports.getFavicon = exports.range = exports.isBigNumber = exports.ensureParsedJSONObject = exports.ensureBN = exports.ensureRegExpString = exports.ensureIntNumber = exports.ensureBuffer = exports.ensureAddressString = exports.ensureEvenLengthHexString = exports.ensureHexString = exports.isHexString = exports.prepend0x = exports.strip0x = exports.has0xPrefix = exports.hexStringFromIntNumber = exports.intNumberFromHexString = exports.bigIntStringFromBN = exports.hexStringFromBuffer = exports.hexStringToUint8Array = exports.uint8ArrayToHex = exports.randomBytesHex = void 0;
const bn_js_1 = __importDefault(require("bn.js"));
exports.showDeprecationWarning = exports.areAddressArraysEqual = exports.getFavicon = exports.range = exports.isBigNumber = exports.ensureParsedJSONObject = exports.ensureBigInt = exports.ensureRegExpString = exports.ensureIntNumber = exports.ensureBuffer = exports.ensureAddressString = exports.ensureEvenLengthHexString = exports.ensureHexString = exports.isHexString = exports.prepend0x = exports.strip0x = exports.has0xPrefix = exports.hexStringFromIntNumber = exports.intNumberFromHexString = exports.bigIntStringFromBigInt = exports.hexStringFromBuffer = exports.hexStringToUint8Array = exports.uint8ArrayToHex = exports.randomBytesHex = void 0;
const error_1 = require("./error");

@@ -34,12 +29,12 @@ const type_1 = require("./type");

exports.hexStringFromBuffer = hexStringFromBuffer;
function bigIntStringFromBN(bn) {
return (0, type_1.BigIntString)(bn.toString(10));
function bigIntStringFromBigInt(bi) {
return (0, type_1.BigIntString)(bi.toString(10));
}
exports.bigIntStringFromBN = bigIntStringFromBN;
exports.bigIntStringFromBigInt = bigIntStringFromBigInt;
function intNumberFromHexString(hex) {
return (0, type_1.IntNumber)(new bn_js_1.default(ensureEvenLengthHexString(hex, false), 16).toNumber());
return (0, type_1.IntNumber)(Number(BigInt(ensureEvenLengthHexString(hex, true))));
}
exports.intNumberFromHexString = intNumberFromHexString;
function hexStringFromIntNumber(num) {
return (0, type_1.HexString)(`0x${new bn_js_1.default(num).toString(16)}`);
return (0, type_1.HexString)(`0x${BigInt(num).toString(16)}`);
}

@@ -124,3 +119,3 @@ exports.hexStringFromIntNumber = hexStringFromIntNumber;

if (isHexString(num)) {
return (0, type_1.IntNumber)(new bn_js_1.default(ensureEvenLengthHexString(num, false), 16).toNumber());
return (0, type_1.IntNumber)(Number(BigInt(ensureEvenLengthHexString(num, true))));
}

@@ -138,15 +133,15 @@ }

exports.ensureRegExpString = ensureRegExpString;
function ensureBN(val) {
if (val !== null && (bn_js_1.default.isBN(val) || isBigNumber(val))) {
return new bn_js_1.default(val.toString(10), 10);
function ensureBigInt(val) {
if (val !== null && (typeof val === 'bigint' || isBigNumber(val))) {
return BigInt(val.toString(10));
}
if (typeof val === 'number') {
return new bn_js_1.default(ensureIntNumber(val));
return BigInt(ensureIntNumber(val));
}
if (typeof val === 'string') {
if (INT_STRING_REGEX.test(val)) {
return new bn_js_1.default(val, 10);
return BigInt(val);
}
if (isHexString(val)) {
return new bn_js_1.default(ensureEvenLengthHexString(val, false), 16);
return BigInt(ensureEvenLengthHexString(val, true));
}

@@ -156,3 +151,3 @@ }

}
exports.ensureBN = ensureBN;
exports.ensureBigInt = ensureBigInt;
function ensureParsedJSONObject(val) {

@@ -199,40 +194,9 @@ if (typeof val === 'string') {

exports.getFavicon = getFavicon;
function createQrUrl(sessionId, sessionSecret, serverUrl, isParentConnection, version, chainId) {
const sessionIdKey = isParentConnection ? 'parent-id' : 'id';
const query = new URLSearchParams({
[sessionIdKey]: sessionId,
secret: sessionSecret,
server: serverUrl,
v: version,
chainId: chainId.toString(),
}).toString();
const qrUrl = `${serverUrl}/#/link?${query}`;
return qrUrl;
function areAddressArraysEqual(arr1, arr2) {
return arr1.length === arr2.length && arr1.every((value, index) => value === arr2[index]);
}
exports.createQrUrl = createQrUrl;
function isInIFrame() {
try {
return window.frameElement !== null;
}
catch (e) {
return false;
}
exports.areAddressArraysEqual = areAddressArraysEqual;
function showDeprecationWarning(oldMethod, instructions) {
console.warn(`EIP1193Provider: ${oldMethod} is deprecated. Please ${instructions} instead.`);
}
exports.isInIFrame = isInIFrame;
function getLocation() {
try {
if (isInIFrame() && window.top) {
return window.top.location;
}
return window.location;
}
catch (e) {
return window.location;
}
}
exports.getLocation = getLocation;
function isMobileWeb() {
var _a;
return /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test((_a = window === null || window === void 0 ? void 0 : window.navigator) === null || _a === void 0 ? void 0 : _a.userAgent);
}
exports.isMobileWeb = isMobileWeb;
exports.showDeprecationWarning = showDeprecationWarning;

@@ -0,5 +1,6 @@

import { CoinbaseWalletProvider } from './CoinbaseWalletProvider';
import { CoinbaseWalletSDK } from './CoinbaseWalletSDK';
import { CoinbaseWalletProvider } from './provider/CoinbaseWalletProvider';
import { ProviderInterface } from './core/type/ProviderInterface';
export { CoinbaseWalletSDK } from './CoinbaseWalletSDK';
export { CoinbaseWalletProvider } from './provider/CoinbaseWalletProvider';
export type { ConnectionPreference } from './core/communicator/ConnectionPreference';
export default CoinbaseWalletSDK;

@@ -10,20 +11,5 @@ declare global {

CoinbaseWalletProvider: typeof CoinbaseWalletProvider;
/**
* For CoinbaseWalletSDK, window.ethereum is `CoinbaseWalletProvider`
*/
ethereum?: any;
coinbaseWalletExtension?: CoinbaseWalletProvider;
/**
* @deprecated Legacy API
*/
WalletLink: typeof CoinbaseWalletSDK;
/**
* @deprecated Legacy API
*/
WalletLinkProvider: typeof CoinbaseWalletProvider;
/**
* @deprecated Legacy API
*/
walletLinkExtension?: CoinbaseWalletProvider;
ethereum?: ProviderInterface;
coinbaseWalletExtension?: ProviderInterface;
}
}
"use strict";
// Copyright (c) 2018-2023 Coinbase, Inc. <https://www.coinbase.com/>
// Licensed under the Apache License, version 2.0
// Copyright (c) 2018-2024 Coinbase, Inc. <https://www.coinbase.com/>
Object.defineProperty(exports, "__esModule", { value: true });
exports.CoinbaseWalletProvider = exports.CoinbaseWalletSDK = void 0;
exports.CoinbaseWalletSDK = void 0;
const CoinbaseWalletProvider_1 = require("./CoinbaseWalletProvider");
const CoinbaseWalletSDK_1 = require("./CoinbaseWalletSDK");
const CoinbaseWalletProvider_1 = require("./provider/CoinbaseWalletProvider");
var CoinbaseWalletSDK_2 = require("./CoinbaseWalletSDK");
Object.defineProperty(exports, "CoinbaseWalletSDK", { enumerable: true, get: function () { return CoinbaseWalletSDK_2.CoinbaseWalletSDK; } });
var CoinbaseWalletProvider_2 = require("./provider/CoinbaseWalletProvider");
Object.defineProperty(exports, "CoinbaseWalletProvider", { enumerable: true, get: function () { return CoinbaseWalletProvider_2.CoinbaseWalletProvider; } });
exports.default = CoinbaseWalletSDK_1.CoinbaseWalletSDK;

@@ -16,10 +13,2 @@ if (typeof window !== 'undefined') {

window.CoinbaseWalletProvider = CoinbaseWalletProvider_1.CoinbaseWalletProvider;
/**
* @deprecated Use `window.CoinbaseWalletSDK`
*/
window.WalletLink = CoinbaseWalletSDK_1.CoinbaseWalletSDK;
/**
* @deprecated Use `window.CoinbaseWalletProvider`
*/
window.WalletLinkProvider = CoinbaseWalletProvider_1.CoinbaseWalletProvider;
}
// Extracted from https://github.com/ethereumjs/ethereumjs-abi and stripped out irrelevant code
// Original code licensed under the MIT License - Copyright (c) 2015 Alex Beregszaszi
/* eslint-disable */
//prettier-ignore
const util = require('./util')
const BN = require('bn.js')

@@ -52,12 +53,5 @@ // Convert from short to canonical names

var type = typeof arg
if (type === 'string') {
if (util.isHexString(arg)) {
return new BN(util.stripHexPrefix(arg), 16)
} else {
return new BN(arg, 10)
}
} else if (type === 'number') {
return new BN(arg)
} else if (arg.toArray) {
// assume this is a BN for the moment, replace with BN.isBN soon
if (type === 'string' || type === 'number') {
return BigInt(arg)
} else if (type === 'bigint') {
return arg

@@ -127,4 +121,5 @@ } else {

num = parseNumber(arg)
if (num.bitLength() > size) {
throw new Error('Supplied uint exceeds width: ' + size + ' vs ' + num.bitLength())
const bitLength = util.bitLengthFromBigInt(num)
if (bitLength > size) {
throw new Error('Supplied uint exceeds width: ' + size + ' vs ' + bitLength)
}

@@ -136,3 +131,3 @@

return num.toArrayLike(Buffer, 'be', 32)
return util.bufferBEFromBigInt(num, 32);
} else if (type.startsWith('int')) {

@@ -145,7 +140,10 @@ size = parseTypeN(type)

num = parseNumber(arg)
if (num.bitLength() > size) {
throw new Error('Supplied int exceeds width: ' + size + ' vs ' + num.bitLength())
const bitLength = util.bitLengthFromBigInt(num)
if (bitLength > size) {
throw new Error('Supplied int exceeds width: ' + size + ' vs ' + bitLength)
}
return num.toTwos(256).toArrayLike(Buffer, 'be', 32)
const twos = util.twosFromBigInt(num, 256);
return util.bufferBEFromBigInt(twos, 32);
} else if (type.startsWith('ufixed')) {

@@ -160,7 +158,7 @@ size = parseTypeNxM(type)

return encodeSingle('uint256', num.mul(new BN(2).pow(new BN(size[1]))))
return encodeSingle('uint256', num * BigInt(2) ** BigInt(size[1]))
} else if (type.startsWith('fixed')) {
size = parseTypeNxM(type)
return encodeSingle('int256', parseNumber(arg).mul(new BN(2).pow(new BN(size[1]))))
return encodeSingle('int256', parseNumber(arg) * BigInt(2) ** BigInt(size[1]))
}

@@ -243,7 +241,8 @@

num = parseNumber(value)
if (num.bitLength() > size) {
throw new Error('Supplied uint exceeds width: ' + size + ' vs ' + num.bitLength())
const bitLength = util.bitLengthFromBigInt(num)
if (bitLength > size) {
throw new Error('Supplied uint exceeds width: ' + size + ' vs ' + bitLength)
}
ret.push(num.toArrayLike(Buffer, 'be', size / 8))
ret.push(util.bufferBEFromBigInt(num, size / 8))
} else if (type.startsWith('int')) {

@@ -256,7 +255,9 @@ size = parseTypeN(type)

num = parseNumber(value)
if (num.bitLength() > size) {
throw new Error('Supplied int exceeds width: ' + size + ' vs ' + num.bitLength())
const bitLength = util.bitLengthFromBigInt(num)
if (bitLength > size) {
throw new Error('Supplied int exceeds width: ' + size + ' vs ' + bitLength)
}
ret.push(num.toTwos(size).toArrayLike(Buffer, 'be', size / 8))
const twos = util.twosFromBigInt(num, size);
ret.push(util.bufferBEFromBigInt(twos, size / 8))
} else {

@@ -263,0 +264,0 @@ // FIXME: support all other types

// Extracted from https://github.com/ethereumjs/ethereumjs-util and stripped out irrelevant code
// Original code licensed under the Mozilla Public License Version 2.0
/* eslint-disable */
//prettier-ignore
const createKeccakHash = require('keccak/js')
const BN = require('bn.js')

@@ -17,2 +18,37 @@ /**

function bitLengthFromBigInt (num) {
return num.toString(2).length
}
function bufferBEFromBigInt(num, length) {
let hex = num.toString(16);
// Ensure the hex string length is even
if (hex.length % 2 !== 0) hex = '0' + hex;
// Convert hex string to a byte array
const byteArray = hex.match(/.{1,2}/g).map(byte => parseInt(byte, 16));
// Ensure the byte array is of the specified length
while (byteArray.length < length) {
byteArray.unshift(0); // Prepend with zeroes if shorter than required length
}
return Buffer.from(byteArray);
}
function twosFromBigInt(value, width) {
const isNegative = value < 0n;
let result;
if (isNegative) {
// Prepare a mask for the specified width to perform NOT operation
const mask = (1n << BigInt(width)) - 1n;
// Invert bits (using NOT) and add one
result = (~value & mask) + 1n;
} else {
result = value;
}
// Ensure the result fits in the specified width
result &= (1n << BigInt(width)) - 1n;
return result;
}
/**

@@ -57,3 +93,3 @@ * Left Pads an `Array` or `Buffer` with leading zeros till it has `length` bytes.

/**
* Attempts to turn a value into a `Buffer`. As input it supports `Buffer`, `String`, `Number`, null/undefined, `BN` and other objects with a `toArray()` method.
* Attempts to turn a value into a `Buffer`. As input it supports `Buffer`, `String`, `Number`, null/undefined, `BIgInt` and other objects with a `toArray()` method.
* @param {*} v the value

@@ -75,6 +111,7 @@ */

v = Buffer.allocUnsafe(0)
} else if (BN.isBN(v)) {
v = v.toArrayLike(Buffer)
} else if (typeof v === 'bigint') {
v = bufferBEFromBigInt(v)
} else if (v.toArray) {
// converts a BN to a Buffer
// TODO: bigint should be handled above, may remove this duplicate
// converts a BigInt to a Buffer
v = Buffer.from(v.toArray())

@@ -134,3 +171,6 @@ } else {

bufferToHex,
keccak
keccak,
bitLengthFromBigInt,
bufferBEFromBigInt,
twosFromBigInt
}

@@ -1,1 +0,1 @@

export declare const LIB_VERSION = "3.9.2";
export declare const LIB_VERSION = "4.0.0-beta.0";
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.LIB_VERSION = void 0;
exports.LIB_VERSION = '3.9.2';
exports.LIB_VERSION = '4.0.0-beta.0';
{
"name": "@coinbase/wallet-sdk",
"version": "3.9.2",
"version": "4.0.0-beta.0",
"description": "Coinbase Wallet JavaScript SDK",

@@ -31,4 +31,4 @@ "keywords": [

"prebuild": "rm -rf ./build && node -p \"'export const LIB_VERSION = \\'' + require('./package.json').version + '\\';'\" > src/version.ts",
"build": "node compile-assets.js && tsc -p ./tsconfig.build.json && cp -a src/vendor-js dist",
"dev": "node compile-assets.js && tsc --watch",
"build": "node compile-assets.js && tsc -p ./tsconfig.build.json && tsc-alias && cp -a src/vendor-js dist",
"dev": "node compile-assets.js && tsc --watch & nodemon --watch dist --delay 1 --exec tsc-alias",
"typecheck": "tsc --noEmit",

@@ -38,3 +38,2 @@ "lint": "eslint . --ext .ts,.tsx --fix"

"dependencies": {
"bn.js": "^5.2.1",
"buffer": "^6.0.3",

@@ -59,3 +58,2 @@ "clsx": "^1.2.1",

"@testing-library/preact": "^2.0.1",
"@types/bn.js": "^4.11.6",
"@types/jest": "^27.5.2",

@@ -68,2 +66,3 @@ "@types/node": "^14.18.54",

"jest-websocket-mock": "^2.4.0",
"nodemon": "^3.1.0",
"prettier": "^2.8.8",

@@ -73,2 +72,3 @@ "sass": "^1.64.1",

"ts-node": "^10.9.1",
"tsc-alias": "^1.8.8",
"tslib": "^2.6.0",

@@ -75,0 +75,0 @@ "typescript": "^5.1.6"

@@ -111,17 +111,1 @@ # Coinbase Wallet SDK

- [eth-block-tracker](https://github.com/MetaMask/eth-block-tracker/blob/master/LICENSE) under the MIT license
```
Copyright © 2018-2023 Coinbase, Inc. <https://www.coinbase.com/>
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
```
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc