@near-js/keystores-node
Advanced tools
Comparing version 0.0.12 to 0.1.0-next.0
@@ -1,6 +0,1 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.UnencryptedFileSystemKeyStore = exports.readKeyFile = void 0; | ||
var unencrypted_file_system_keystore_1 = require("./unencrypted_file_system_keystore"); | ||
Object.defineProperty(exports, "readKeyFile", { enumerable: true, get: function () { return unencrypted_file_system_keystore_1.readKeyFile; } }); | ||
Object.defineProperty(exports, "UnencryptedFileSystemKeyStore", { enumerable: true, get: function () { return unencrypted_file_system_keystore_1.UnencryptedFileSystemKeyStore; } }); | ||
export { readKeyFile, UnencryptedFileSystemKeyStore } from './unencrypted_file_system_keystore'; |
@@ -1,21 +0,6 @@ | ||
"use strict"; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.UnencryptedFileSystemKeyStore = exports.readKeyFile = void 0; | ||
const crypto_1 = require("@near-js/crypto"); | ||
const keystores_1 = require("@near-js/keystores"); | ||
const fs_1 = __importDefault(require("fs")); | ||
const path_1 = __importDefault(require("path")); | ||
const util_1 = require("util"); | ||
import { KeyPair } from '@near-js/crypto'; | ||
import { KeyStore } from '@near-js/keystores'; | ||
import fs from 'fs'; | ||
import path from 'path'; | ||
import { promisify as _promisify } from 'util'; | ||
/* remove for versions not referenced by near-api-js */ | ||
@@ -28,42 +13,35 @@ const promisify = (fn) => { | ||
} | ||
return (0, util_1.promisify)(fn); | ||
return _promisify(fn); | ||
}; | ||
const exists = promisify(fs_1.default.exists); | ||
const readFile = promisify(fs_1.default.readFile); | ||
const writeFile = promisify(fs_1.default.writeFile); | ||
const unlink = promisify(fs_1.default.unlink); | ||
const readdir = promisify(fs_1.default.readdir); | ||
const mkdir = promisify(fs_1.default.mkdir); | ||
const exists = promisify(fs.exists); | ||
const readFile = promisify(fs.readFile); | ||
const writeFile = promisify(fs.writeFile); | ||
const unlink = promisify(fs.unlink); | ||
const readdir = promisify(fs.readdir); | ||
const mkdir = promisify(fs.mkdir); | ||
/** @hidden */ | ||
function loadJsonFile(filename) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const content = yield readFile(filename); | ||
return JSON.parse(content.toString()); | ||
}); | ||
async function loadJsonFile(filename) { | ||
const content = await readFile(filename); | ||
return JSON.parse(content.toString()); | ||
} | ||
function ensureDir(dir) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
try { | ||
yield mkdir(dir, { recursive: true }); | ||
async function ensureDir(dir) { | ||
try { | ||
await mkdir(dir, { recursive: true }); | ||
} | ||
catch (err) { | ||
if (err.code !== 'EEXIST') { | ||
throw err; | ||
} | ||
catch (err) { | ||
if (err.code !== 'EEXIST') { | ||
throw err; | ||
} | ||
} | ||
}); | ||
} | ||
} | ||
/** @hidden */ | ||
function readKeyFile(filename) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const accountInfo = yield loadJsonFile(filename); | ||
// The private key might be in private_key or secret_key field. | ||
let privateKey = accountInfo.private_key; | ||
if (!privateKey && accountInfo.secret_key) { | ||
privateKey = accountInfo.secret_key; | ||
} | ||
return [accountInfo.account_id, crypto_1.KeyPair.fromString(privateKey)]; | ||
}); | ||
export async function readKeyFile(filename) { | ||
const accountInfo = await loadJsonFile(filename); | ||
// The private key might be in private_key or secret_key field. | ||
let privateKey = accountInfo.private_key; | ||
if (!privateKey && accountInfo.secret_key) { | ||
privateKey = accountInfo.secret_key; | ||
} | ||
return [accountInfo.account_id, KeyPair.fromString(privateKey)]; | ||
} | ||
exports.readKeyFile = readKeyFile; | ||
/** | ||
@@ -92,3 +70,5 @@ * This class is used to store keys on the file system. | ||
*/ | ||
class UnencryptedFileSystemKeyStore extends keystores_1.KeyStore { | ||
export class UnencryptedFileSystemKeyStore extends KeyStore { | ||
/** @hidden */ | ||
keyDir; | ||
/** | ||
@@ -99,3 +79,3 @@ * @param keyDir base directory for key storage. Keys will be stored in `keyDir/networkId/accountId.json` | ||
super(); | ||
this.keyDir = path_1.default.resolve(keyDir); | ||
this.keyDir = path.resolve(keyDir); | ||
} | ||
@@ -108,8 +88,6 @@ /** | ||
*/ | ||
setKey(networkId, accountId, keyPair) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
yield ensureDir(`${this.keyDir}/${networkId}`); | ||
const content = { account_id: accountId, public_key: keyPair.getPublicKey().toString(), private_key: keyPair.toString() }; | ||
yield writeFile(this.getKeyFilePath(networkId, accountId), JSON.stringify(content), { mode: 0o600 }); | ||
}); | ||
async setKey(networkId, accountId, keyPair) { | ||
await ensureDir(`${this.keyDir}/${networkId}`); | ||
const content = { account_id: accountId, public_key: keyPair.getPublicKey().toString(), private_key: keyPair.toString() }; | ||
await writeFile(this.getKeyFilePath(networkId, accountId), JSON.stringify(content), { mode: 0o600 }); | ||
} | ||
@@ -122,11 +100,9 @@ /** | ||
*/ | ||
getKey(networkId, accountId) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
// Find key / account id. | ||
if (!(yield exists(this.getKeyFilePath(networkId, accountId)))) { | ||
return null; | ||
} | ||
const accountKeyPair = yield readKeyFile(this.getKeyFilePath(networkId, accountId)); | ||
return accountKeyPair[1]; | ||
}); | ||
async getKey(networkId, accountId) { | ||
// Find key / account id. | ||
if (!await exists(this.getKeyFilePath(networkId, accountId))) { | ||
return null; | ||
} | ||
const accountKeyPair = await readKeyFile(this.getKeyFilePath(networkId, accountId)); | ||
return accountKeyPair[1]; | ||
} | ||
@@ -138,8 +114,6 @@ /** | ||
*/ | ||
removeKey(networkId, accountId) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
if (yield exists(this.getKeyFilePath(networkId, accountId))) { | ||
yield unlink(this.getKeyFilePath(networkId, accountId)); | ||
} | ||
}); | ||
async removeKey(networkId, accountId) { | ||
if (await exists(this.getKeyFilePath(networkId, accountId))) { | ||
await unlink(this.getKeyFilePath(networkId, accountId)); | ||
} | ||
} | ||
@@ -149,10 +123,8 @@ /** | ||
*/ | ||
clear() { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
for (const network of yield this.getNetworks()) { | ||
for (const account of yield this.getAccounts(network)) { | ||
yield this.removeKey(network, account); | ||
} | ||
async clear() { | ||
for (const network of await this.getNetworks()) { | ||
for (const account of await this.getAccounts(network)) { | ||
await this.removeKey(network, account); | ||
} | ||
}); | ||
} | ||
} | ||
@@ -167,11 +139,9 @@ /** @hidden */ | ||
*/ | ||
getNetworks() { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const files = yield readdir(this.keyDir); | ||
const result = new Array(); | ||
files.forEach((item) => { | ||
result.push(item); | ||
}); | ||
return result; | ||
async getNetworks() { | ||
const files = await readdir(this.keyDir); | ||
const result = new Array(); | ||
files.forEach((item) => { | ||
result.push(item); | ||
}); | ||
return result; | ||
} | ||
@@ -182,12 +152,10 @@ /** | ||
*/ | ||
getAccounts(networkId) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
if (!(yield exists(`${this.keyDir}/${networkId}`))) { | ||
return []; | ||
} | ||
const files = yield readdir(`${this.keyDir}/${networkId}`); | ||
return files | ||
.filter(file => file.endsWith('.json')) | ||
.map(file => file.replace(/.json$/, '')); | ||
}); | ||
async getAccounts(networkId) { | ||
if (!await exists(`${this.keyDir}/${networkId}`)) { | ||
return []; | ||
} | ||
const files = await readdir(`${this.keyDir}/${networkId}`); | ||
return files | ||
.filter(file => file.endsWith('.json')) | ||
.map(file => file.replace(/.json$/, '')); | ||
} | ||
@@ -199,2 +167,1 @@ /** @hidden */ | ||
} | ||
exports.UnencryptedFileSystemKeyStore = UnencryptedFileSystemKeyStore; |
{ | ||
"name": "@near-js/keystores-node", | ||
"version": "0.0.12", | ||
"version": "0.1.0-next.0", | ||
"description": "KeyStore implementation for working with keys in the local filesystem", | ||
"main": "lib/index.js", | ||
"type": "module", | ||
"keywords": [], | ||
@@ -10,10 +11,12 @@ "author": "", | ||
"dependencies": { | ||
"@near-js/crypto": "1.2.4", | ||
"@near-js/keystores": "0.0.12" | ||
"@near-js/crypto": "1.3.0-next.0", | ||
"@near-js/keystores": "0.1.0-next.0" | ||
}, | ||
"devDependencies": { | ||
"@types/node": "18.11.18", | ||
"jest": "26.0.1", | ||
"ts-jest": "26.5.6", | ||
"typescript": "4.9.4" | ||
"@jest/globals": "^29.7.0", | ||
"@types/node": "20.0.0", | ||
"jest": "29.7.0", | ||
"ts-jest": "29.1.5", | ||
"typescript": "5.4.5", | ||
"tsconfig": "0.0.0" | ||
}, | ||
@@ -26,8 +29,6 @@ "files": [ | ||
"compile": "tsc -p tsconfig.json", | ||
"lint:js": "eslint -c ../../.eslintrc.js.yml test/**/*.js --no-eslintrc", | ||
"lint:js:fix": "eslint -c ../../.eslintrc.js.yml test/**/*.js --no-eslintrc --fix", | ||
"lint:ts": "eslint -c ../../.eslintrc.ts.yml src/**/*.ts --no-eslintrc", | ||
"lint:ts:fix": "eslint -c ../../.eslintrc.ts.yml src/**/*.ts --no-eslintrc --fix", | ||
"test": "jest test" | ||
"lint": "eslint -c ../../.eslintrc.ts.yml src/**/*.ts test/**/*.ts --no-eslintrc", | ||
"lint:fix": "eslint -c ../../.eslintrc.ts.yml src/**/*.ts test/**/*.ts --no-eslintrc --fix", | ||
"test": "jest" | ||
} | ||
} |
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
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
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
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
Yes
12401
6
232
+ Added@near-js/crypto@1.3.0-next.0(transitive)
+ Added@near-js/keystores@0.1.0-next.0(transitive)
+ Added@near-js/types@0.3.0-next.0(transitive)
+ Added@near-js/utils@0.3.0-next.0(transitive)
+ Addedbn.js@4.12.0(transitive)
+ Addedbrorand@1.1.0(transitive)
+ Addedelliptic@6.5.7(transitive)
+ Addedhash.js@1.1.7(transitive)
+ Addedhmac-drbg@1.0.1(transitive)
+ Addedinherits@2.0.4(transitive)
+ Addedminimalistic-assert@1.0.1(transitive)
+ Addedminimalistic-crypto-utils@1.0.1(transitive)
+ Addednode-addon-api@5.1.0(transitive)
+ Addednode-gyp-build@4.8.2(transitive)
+ Addedsecp256k1@5.0.0(transitive)
- Removed@near-js/crypto@1.2.4(transitive)
- Removed@near-js/keystores@0.0.12(transitive)
- Removed@near-js/types@0.2.1(transitive)
- Removed@near-js/utils@0.2.2(transitive)
Updated@near-js/crypto@1.3.0-next.0