Socket
Socket
Sign inDemoInstall

near-api-js

Package Overview
Dependencies
Maintainers
1
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.29.0 to 0.29.1

4

lib/key_stores/unencrypted_file_system_keystore.d.ts
import { KeyPair } from '../utils/key_pair';
import { KeyStore } from './keystore';
export declare function loadJsonFile(path: string): Promise<any>;
export declare function readKeyFile(path: string): Promise<[string, KeyPair]>;
export declare function loadJsonFile(filename: string): Promise<any>;
export declare function readKeyFile(filename: string): Promise<[string, KeyPair]>;
export declare class UnencryptedFileSystemKeyStore extends KeyStore {

@@ -6,0 +6,0 @@ readonly keyDir: string;

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

const fs_1 = __importDefault(require("fs"));
const path_1 = __importDefault(require("path"));
const util_1 = require("util");

@@ -26,10 +27,10 @@ const key_pair_1 = require("../utils/key_pair");

const mkdir = promisify(fs_1.default.mkdir);
async function loadJsonFile(path) {
const content = await readFile(path);
async function loadJsonFile(filename) {
const content = await readFile(filename);
return JSON.parse(content.toString());
}
exports.loadJsonFile = loadJsonFile;
async function ensureDir(path) {
async function ensureDir(dir) {
try {
await mkdir(path, { recursive: true });
await mkdir(dir, { recursive: true });
}

@@ -42,4 +43,4 @@ catch (err) {

}
async function readKeyFile(path) {
const accountInfo = await loadJsonFile(path);
async function readKeyFile(filename) {
const accountInfo = await loadJsonFile(filename);
// The private key might be in private_key or secret_key field.

@@ -56,3 +57,3 @@ let privateKey = accountInfo.private_key;

super();
this.keyDir = keyDir;
this.keyDir = path_1.default.resolve(keyDir);
}

@@ -59,0 +60,0 @@ /**

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

// TODO: Fix when https://github.com/nearprotocol/nearcore/issues/1839 gets resolved
if (response.error.data === 'Timeout') {
if (response.error.data === 'Timeout' || errorMessage.includes('Timeout error')) {
throw new errors_1.TypedError('send_tx_commit has timed out.', 'TimeoutError');

@@ -157,0 +157,0 @@ }

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

export declare function deleteAccount(beneficiaryId: string): Action;
declare class Signature extends Assignable {
export declare class Signature extends Assignable {
keyType: KeyType;

@@ -73,0 +73,0 @@ data: Uint8Array;

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

Object.defineProperty(exports, "__esModule", { value: true });
exports.signTransaction = exports.createTransaction = exports.SCHEMA = exports.Action = exports.SignedTransaction = exports.Transaction = exports.deleteAccount = exports.deleteKey = exports.addKey = exports.stake = exports.transfer = exports.functionCall = exports.deployContract = exports.createAccount = exports.IAction = exports.functionCallAccessKey = exports.fullAccessKey = exports.AccessKey = exports.AccessKeyPermission = exports.FullAccessPermission = exports.FunctionCallPermission = void 0;
exports.signTransaction = exports.createTransaction = exports.SCHEMA = exports.Action = exports.SignedTransaction = exports.Transaction = exports.Signature = exports.deleteAccount = exports.deleteKey = exports.addKey = exports.stake = exports.transfer = exports.functionCall = exports.deployContract = exports.createAccount = exports.IAction = exports.functionCallAccessKey = exports.fullAccessKey = exports.AccessKey = exports.AccessKeyPermission = exports.FullAccessPermission = exports.FunctionCallPermission = void 0;
const js_sha256_1 = __importDefault(require("js-sha256"));

@@ -97,2 +97,3 @@ const enums_1 = require("./utils/enums");

}
exports.Signature = Signature;
class Transaction extends enums_1.Assignable {

@@ -99,0 +100,0 @@ encode() {

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

const LOGIN_WALLET_URL_SUFFIX = '/login/';
const MULTISIG_HAS_METHOD = 'add_request_and_confirm';
const LOCAL_STORAGE_KEY_SUFFIX = '_wallet_auth_key';

@@ -199,2 +200,9 @@ const PENDING_ACCESS_KEY_PREFIX = 'pending_key'; // browser storage key for a pending access key (i.e. key has been generated but we are not sure it was added yet)

const { receiver_id: allowedReceiverId, method_names: allowedMethods } = permission.FunctionCall;
/********************************
Accept multisig access keys and let wallets attempt to signAndSendTransaction
If an access key has itself as receiverId and method permission add_request_and_confirm, then it is being used in a wallet with multisig contract: https://github.com/near/core-contracts/blob/671c05f09abecabe7a7e58efe942550a35fc3292/multisig/src/lib.rs#L149-L153
********************************/
if (allowedReceiverId === this.accountId && allowedMethods.includes(MULTISIG_HAS_METHOD)) {
return true;
}
if (allowedReceiverId === receiverId) {

@@ -201,0 +209,0 @@ if (actions.length !== 1) {

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

@@ -6,0 +6,0 @@ "type": "git",

import fs from 'fs';
import path from 'path';
import { promisify as _promisify } from 'util';

@@ -32,10 +33,10 @@

export async function loadJsonFile(path: string): Promise<any> {
const content = await readFile(path);
export async function loadJsonFile(filename: string): Promise<any> {
const content = await readFile(filename);
return JSON.parse(content.toString());
}
async function ensureDir(path: string): Promise<void> {
async function ensureDir(dir: string): Promise<void> {
try {
await mkdir(path, { recursive: true });
await mkdir(dir, { recursive: true });
} catch (err) {

@@ -46,4 +47,4 @@ if (err.code !== 'EEXIST') { throw err; }

export async function readKeyFile(path: string): Promise<[string, KeyPair]> {
const accountInfo = await loadJsonFile(path);
export async function readKeyFile(filename: string): Promise<[string, KeyPair]> {
const accountInfo = await loadJsonFile(filename);
// The private key might be in private_key or secret_key field.

@@ -62,3 +63,3 @@ let privateKey = accountInfo.private_key;

super();
this.keyDir = keyDir;
this.keyDir = path.resolve(keyDir);
}

@@ -65,0 +66,0 @@

@@ -170,3 +170,3 @@ import depd from 'depd';

// TODO: Fix when https://github.com/nearprotocol/nearcore/issues/1839 gets resolved
if (response.error.data === 'Timeout') {
if (response.error.data === 'Timeout' || errorMessage.includes('Timeout error')) {
throw new TypedError('send_tx_commit has timed out.', 'TimeoutError');

@@ -173,0 +173,0 @@ } else {

@@ -90,3 +90,3 @@ import sha256 from 'js-sha256';

class Signature extends Assignable {
export class Signature extends Assignable {
keyType: KeyType;

@@ -93,0 +93,0 @@ data: Uint8Array;

@@ -12,3 +12,3 @@ import { Account } from './account';

const LOGIN_WALLET_URL_SUFFIX = '/login/';
const MULTISIG_HAS_METHOD = 'add_request_and_confirm';
const LOCAL_STORAGE_KEY_SUFFIX = '_wallet_auth_key';

@@ -234,2 +234,9 @@ const PENDING_ACCESS_KEY_PREFIX = 'pending_key'; // browser storage key for a pending access key (i.e. key has been generated but we are not sure it was added yet)

const { receiver_id: allowedReceiverId, method_names: allowedMethods } = permission.FunctionCall;
/********************************
Accept multisig access keys and let wallets attempt to signAndSendTransaction
If an access key has itself as receiverId and method permission add_request_and_confirm, then it is being used in a wallet with multisig contract: https://github.com/near/core-contracts/blob/671c05f09abecabe7a7e58efe942550a35fc3292/multisig/src/lib.rs#L149-L153
********************************/
if (allowedReceiverId === this.accountId && allowedMethods.includes(MULTISIG_HAS_METHOD)) {
return true;
}
if (allowedReceiverId === receiverId) {

@@ -236,0 +243,0 @@ if (actions.length !== 1) {

@@ -9,2 +9,3 @@

const fs = require('fs');
const path = require('path');

@@ -24,2 +25,6 @@ const KEYSTORE_PATH = '../test-keys';

it('test path resolve', async() => {
expect(ctx.keyStore.keyDir).toEqual(path.join(process.cwd(), KEYSTORE_PATH));
});
it('test public key exists', async () => {

@@ -26,0 +31,0 @@ const key1 = KeyPair.fromRandom();

@@ -5,2 +5,5 @@ const url = require('url');

// If an access key has itself as receiverId and method permission add_request_and_confirm, then it is being used in a wallet with multisig contract: https://github.com/near/core-contracts/blob/671c05f09abecabe7a7e58efe942550a35fc3292/multisig/src/lib.rs#L149-L153
const MULTISIG_HAS_METHOD = 'add_request_and_confirm';
let lastRedirectUrl;

@@ -232,3 +235,3 @@ let lastTransaction;

});
keyStore.setKey('networkId', 'signer.near', localKeyPair);
await keyStore.setKey('networkId', 'signer.near', localKeyPair);

@@ -248,2 +251,67 @@ try {

it('requests transaction signing with 2fa access key', async () => {
let localKeyPair = nearApi.KeyPair.fromRandom('ed25519');
let walletKeyPair = nearApi.KeyPair.fromRandom('ed25519');
setupWalletConnectionForSigning({
allKeys: [ walletKeyPair.publicKey.toString() ],
accountAccessKeys: [{
access_key: {
nonce: 1,
permission: {
FunctionCall: {
allowance: '1000000000',
receiver_id: 'signer.near',
method_names: [MULTISIG_HAS_METHOD]
}
}
},
public_key: localKeyPair.publicKey.toString()
}]
});
await keyStore.setKey('networkId', 'signer.near', localKeyPair);
let res;
try {
res = await walletConnection.account().signAndSendTransaction('receiver.near', [
nearApi.transactions.functionCall('someMethod', new Uint8Array(), new BN('1'), new BN('1'))
]);
} catch (e) {
fail('expected transaction outcome');
}
// multisig access key is accepted res is object representing transaction, populated upon wallet redirect to app
expect(res).toHaveProperty('transaction_outcome');
expect(res).toHaveProperty('receipts_outcome');
});
it('fails requests transaction signing without 2fa access key', async () => {
let localKeyPair = nearApi.KeyPair.fromRandom('ed25519');
let walletKeyPair = nearApi.KeyPair.fromRandom('ed25519');
setupWalletConnectionForSigning({
allKeys: [ walletKeyPair.publicKey.toString() ],
accountAccessKeys: [{
access_key: {
nonce: 1,
permission: {
FunctionCall: {
allowance: '1000000000',
receiver_id: 'signer.near',
method_names: ['not_a_valid_2fa_method']
}
}
},
public_key: localKeyPair.publicKey.toString()
}]
});
await keyStore.setKey('networkId', 'signer.near', localKeyPair);
try {
await walletConnection.account().signAndSendTransaction('receiver.near', [
nearApi.transactions.functionCall('someMethod', new Uint8Array(), new BN('1'), new BN('1'))
]);
fail('expected to throw');
} catch (e) {
expect(e.message).toEqual('Cannot find matching key for transaction sent to receiver.near');
}
});
it.each([

@@ -250,0 +318,0 @@ nearApi.transactions.functionCall('someMethod', new Uint8Array(), new BN('1'), new BN('0')),

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