Socket
Socket
Sign inDemoInstall

near-api-js

Package Overview
Dependencies
Maintainers
6
Versions
77
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

near-api-js - npm Package Compare versions

Comparing version 0.43.1 to 0.44.0

1

lib/account.d.ts

@@ -35,2 +35,3 @@ /// <reference types="node" />

walletCallbackUrl?: string;
returnError?: boolean;
}

@@ -37,0 +38,0 @@ /**

4

lib/account.js

@@ -114,3 +114,3 @@ "use strict";

}
async signAndSendTransactionV2({ receiverId, actions }) {
async signAndSendTransactionV2({ receiverId, actions, returnError }) {
let txHash, signedTx;

@@ -155,3 +155,3 @@ // TODO: TX_NONCE (different constants for different uses of exponentialBackoff?)

this.printLogsAndFailures(signedTx.transaction.receiverId, flatLogs);
if (typeof result.status === 'object' && typeof result.status.Failure === 'object') {
if (!returnError && typeof result.status === 'object' && typeof result.status.Failure === 'object') {
// if error data has error_message and error_type properties, we consider that node returned an error in the old format

@@ -158,0 +158,0 @@ if (result.status.Failure.error_message && result.status.Failure.error_type) {

@@ -14,3 +14,3 @@ "use strict";

return config;
case 'JsonRpcProvider': return new providers_1.JsonRpcProvider(config.args.url);
case 'JsonRpcProvider': return new providers_1.JsonRpcProvider({ ...config.args });
default: throw new Error(`Unknown provider type ${config.type}`);

@@ -17,0 +17,0 @@ }

@@ -93,3 +93,3 @@ "use strict";

const content = { account_id: accountId, public_key: keyPair.getPublicKey().toString(), private_key: keyPair.toString() };
await writeFile(this.getKeyFilePath(networkId, accountId), JSON.stringify(content));
await writeFile(this.getKeyFilePath(networkId, accountId), JSON.stringify(content), { mode: 0o600 });
}

@@ -96,0 +96,0 @@ /**

@@ -52,2 +52,9 @@ /**

/**
* NEAR RPC API headers. Can be used to pass API KEY and other parameters.
* @see {@link JsonRpcProvider.JsonRpcProvider | JsonRpcProvider}
*/
headers: {
[key: string]: string | number;
};
/**
* NEAR wallet url used to redirect users to their wallet in browser applications.

@@ -54,0 +61,0 @@ * @see {@link https://docs.near.org/docs/tools/near-wallet}

@@ -33,3 +33,3 @@ "use strict";

networkId: config.networkId,
provider: { type: 'JsonRpcProvider', args: { url: config.nodeUrl } },
provider: { type: 'JsonRpcProvider', args: { url: config.nodeUrl, headers: config.headers } },
signer: config.signer || { type: 'InMemorySigner', keyStore: config.keyStore || config.deps.keyStore }

@@ -36,0 +36,0 @@ });

@@ -15,5 +15,5 @@ import { AccessKeyWithPublicKey, Provider, FinalExecutionOutcome, NodeStatusResult, BlockId, BlockReference, BlockResult, BlockChangeResult, ChangeResult, ChunkId, ChunkResult, EpochValidatorInfo, NearProtocolConfig, LightClientProof, LightClientProofRequest, GasPrice, QueryResponseKind } from './provider';

/**
* @param url RPC API endpoint URL
* @param connectionInfoOrUrl ConnectionInfo or RPC API endpoint URL (deprecated)
*/
constructor(url?: string);
constructor(connectionInfoOrUrl?: string | ConnectionInfo);
/**

@@ -20,0 +20,0 @@ * Gets the RPC's status

@@ -35,7 +35,14 @@ "use strict";

/**
* @param url RPC API endpoint URL
* @param connectionInfoOrUrl ConnectionInfo or RPC API endpoint URL (deprecated)
*/
constructor(url) {
constructor(connectionInfoOrUrl) {
super();
this.connection = { url };
if (connectionInfoOrUrl != null && typeof connectionInfoOrUrl == 'object') {
this.connection = connectionInfoOrUrl;
}
else {
const deprecate = depd_1.default('JsonRpcProvider(url?: string)');
deprecate('use `JsonRpcProvider(connectionInfo: ConnectionInfo)` instead');
this.connection = { url: connectionInfoOrUrl };
}
}

@@ -331,3 +338,5 @@ /**

if (error.type === 'TimeoutError') {
console.warn(`Retrying request to ${method} as it has timed out`, params);
if (!process.env['NEAR_NO_LOGS']) {
console.warn(`Retrying request to ${method} as it has timed out`, params);
}
return null;

@@ -334,0 +343,0 @@ }

@@ -20,2 +20,3 @@ import { Assignable } from './enums';

toString(): string;
verify(message: Uint8Array, signature: Uint8Array): boolean;
}

@@ -22,0 +23,0 @@ export declare abstract class KeyPair {

@@ -52,2 +52,8 @@ "use strict";

}
verify(message, signature) {
switch (this.keyType) {
case KeyType.ED25519: return tweetnacl_1.default.sign.detached.verify(message, signature, this.data);
default: throw new Error(`Unknown key type ${this.keyType}`);
}
}
}

@@ -118,3 +124,3 @@ exports.PublicKey = PublicKey;

verify(message, signature) {
return tweetnacl_1.default.sign.detached.verify(message, signature, this.publicKey.data);
return this.publicKey.verify(message, signature);
}

@@ -121,0 +127,0 @@ toString() {

@@ -11,2 +11,2 @@ export interface ConnectionInfo {

}
export declare function fetchJson(connection: string | ConnectionInfo, json?: string): Promise<any>;
export declare function fetchJson(connectionInfoOrUrl: string | ConnectionInfo, json?: string): Promise<any>;

@@ -14,20 +14,20 @@ "use strict";

const RETRY_NUMBER = 10;
async function fetchJson(connection, json) {
let url = null;
if (typeof (connection) === 'string') {
url = connection;
async function fetchJson(connectionInfoOrUrl, json) {
let connectionInfo = { url: null };
if (typeof (connectionInfoOrUrl) === 'string') {
connectionInfo.url = connectionInfoOrUrl;
}
else {
url = connection.url;
connectionInfo = connectionInfoOrUrl;
}
const response = await exponential_backoff_1.default(START_WAIT_TIME_MS, RETRY_NUMBER, BACKOFF_MULTIPLIER, async () => {
try {
const response = await fetch(url, {
const response = await fetch(connectionInfo.url, {
method: json ? 'POST' : 'GET',
body: json ? json : undefined,
headers: { 'Content-Type': 'application/json; charset=utf-8' }
headers: { ...connectionInfo.headers, 'Content-Type': 'application/json; charset=utf-8' }
});
if (!response.ok) {
if (response.status === 503) {
errors_1.logWarning(`Retrying HTTP request for ${url} as it's not available now`);
errors_1.logWarning(`Retrying HTTP request for ${connectionInfo.url} as it's not available now`);
return null;

@@ -41,3 +41,3 @@ }

if (error.toString().includes('FetchError') || error.toString().includes('Failed to fetch')) {
errors_1.logWarning(`Retrying HTTP request for ${url} because of error: ${error}`);
errors_1.logWarning(`Retrying HTTP request for ${connectionInfo.url} because of error: ${error}`);
return null;

@@ -49,3 +49,3 @@ }

if (!response) {
throw new providers_1.TypedError(`Exceeded ${RETRY_NUMBER} attempts for ${url}.`, 'RetriesExceeded');
throw new providers_1.TypedError(`Exceeded ${RETRY_NUMBER} attempts for ${connectionInfo.url}.`, 'RetriesExceeded');
}

@@ -52,0 +52,0 @@ return await response.json();

@@ -167,2 +167,4 @@ "use strict";

currentUrl.searchParams.delete('account_id');
currentUrl.searchParams.delete('meta');
currentUrl.searchParams.delete('transactionHashes');
window.history.replaceState({}, document.title, currentUrl.toString());

@@ -169,0 +171,0 @@ }

{
"name": "near-api-js",
"description": "JavaScript library to interact with NEAR Protocol via RPC API",
"version": "0.43.1",
"version": "0.44.0",
"repository": {

@@ -36,2 +36,3 @@ "type": "git",

"eslint": "^6.5.1",
"husky": "^7.0.4",
"in-publish": "^2.0.0",

@@ -38,0 +39,0 @@ "jest": "^26.0.1",

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

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