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

nkeys.js

Package Overview
Dependencies
Maintainers
1
Versions
21
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

nkeys.js - npm Package Compare versions

Comparing version 1.0.6-1 to 1.1.0

lib/curve.d.ts

3

lib/helper.d.ts

@@ -16,2 +16,5 @@ /**

randomBytes(len: number): Uint8Array;
scalarBaseMultiply(n: Uint8Array): Uint8Array;
seal(data: Uint8Array, nonce: Uint8Array, pub: Uint8Array, key: Uint8Array): Uint8Array;
open(data: Uint8Array, nonce: Uint8Array, pub: Uint8Array, key: Uint8Array): Uint8Array;
}

@@ -18,0 +21,0 @@ /**

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

sign: nacl.sign.detached,
scalarBaseMultiply: nacl.scalarMult.base,
seal: nacl.box,
open: nacl.box.open,
};

@@ -33,0 +36,0 @@ // This here to support node 10.

@@ -15,2 +15,4 @@ import { KeyPair } from "./nkeys";

clear(): void;
seal(input: Uint8Array, recipient: string, nonce?: Uint8Array): Uint8Array;
open(message: Uint8Array, sender: string): Uint8Array | null;
}
"use strict";
/*
* Copyright 2018-2020 The NATS Authors
* Copyright 2018-2024 The NATS Authors
* Licensed under the Apache License, Version 2.0 (the "License");

@@ -78,3 +78,9 @@ * you may not use this file except in compliance with the License.

}
seal(input, recipient, nonce) {
throw new nkeys_1.NKeysError(nkeys_1.NKeysErrorCode.InvalidNKeyOperation);
}
open(message, sender) {
throw new nkeys_1.NKeysError(nkeys_1.NKeysErrorCode.InvalidNKeyOperation);
}
}
exports.KP = KP;

2

lib/mod.d.ts
export type { KeyPair } from "./nkeys";
export { createAccount, createCluster, createOperator, createPair, createServer, createUser, fromPublic, fromSeed, NKeysError, NKeysErrorCode, Prefix, } from "./nkeys";
export { createAccount, createCluster, createCurve, createOperator, createPair, createServer, createUser, fromCurveSeed, fromPublic, fromSeed, NKeysError, NKeysErrorCode, Prefix, } from "./nkeys";
export { decode, encode } from "./util";
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.encode = exports.decode = exports.Prefix = exports.NKeysErrorCode = exports.NKeysError = exports.fromSeed = exports.fromPublic = exports.createUser = exports.createServer = exports.createPair = exports.createOperator = exports.createCluster = exports.createAccount = void 0;
exports.encode = exports.decode = exports.Prefix = exports.NKeysErrorCode = exports.NKeysError = exports.fromSeed = exports.fromPublic = exports.fromCurveSeed = exports.createUser = exports.createServer = exports.createPair = exports.createOperator = exports.createCurve = exports.createCluster = exports.createAccount = void 0;
var nkeys_1 = require("./nkeys");
Object.defineProperty(exports, "createAccount", { enumerable: true, get: function () { return nkeys_1.createAccount; } });
Object.defineProperty(exports, "createCluster", { enumerable: true, get: function () { return nkeys_1.createCluster; } });
Object.defineProperty(exports, "createCurve", { enumerable: true, get: function () { return nkeys_1.createCurve; } });
Object.defineProperty(exports, "createOperator", { enumerable: true, get: function () { return nkeys_1.createOperator; } });

@@ -11,2 +12,3 @@ Object.defineProperty(exports, "createPair", { enumerable: true, get: function () { return nkeys_1.createPair; } });

Object.defineProperty(exports, "createUser", { enumerable: true, get: function () { return nkeys_1.createUser; } });
Object.defineProperty(exports, "fromCurveSeed", { enumerable: true, get: function () { return nkeys_1.fromCurveSeed; } });
Object.defineProperty(exports, "fromPublic", { enumerable: true, get: function () { return nkeys_1.fromPublic; } });

@@ -13,0 +15,0 @@ Object.defineProperty(exports, "fromSeed", { enumerable: true, get: function () { return nkeys_1.fromSeed; } });

@@ -29,2 +29,6 @@ /**

/**
* @ignore
*/
export declare function createCurve(): KeyPair;
/**
* Creates a KeyPair from a specified public key

@@ -36,2 +40,3 @@ * @param {string} src of the public key in string format.

export declare function fromPublic(src: string): KeyPair;
export declare function fromCurveSeed(src: Uint8Array): KeyPair;
/**

@@ -84,2 +89,4 @@ * Creates a KeyPair from a specified seed.

clear(): void;
seal(input: Uint8Array, recipient: string, nonce?: Uint8Array): Uint8Array;
open(message: Uint8Array, sender: string): Uint8Array | null;
}

@@ -91,9 +98,10 @@ /**

Unknown = -1,
Seed = 144,
Private = 120,
Operator = 112,
Server = 104,
Cluster = 16,
Account = 0,
User = 160
Seed = 144,// Base32-encodes to 'S...'
Private = 120,// Base32-encodes to 'P...'
Operator = 112,// Base32-encodes to 'O...'
Server = 104,// Base32-encodes to 'N...'
Cluster = 16,// Base32-encodes to 'C...'
Account = 0,// Base32-encodes to 'A...'
User = 160,// Base32-encodes to 'U...'
Curve = 184
}

@@ -118,4 +126,9 @@ /**

InvalidSeed = "nkeys: invalid seed",
InvalidCurveSeed = "nkeys: invalid curve seed",
InvalidCurveKey = "nkeys: not a valid curve key",
InvalidCurveOperation = "nkeys: curve key is not valid for sign/verify",
InvalidNKeyOperation = "keys: only curve key can seal/open",
InvalidEncoding = "nkeys: invalid encoded key",
InvalidSignature = "nkeys: signature verification failed",
InvalidRecipient = "nkeys: not a valid recipient public curve key",
InvalidEncrypted = "nkeys: encrypted input is not valid",
CannotSign = "nkeys: cannot sign, no private key available",

@@ -122,0 +135,0 @@ PublicKeyOnly = "nkeys: no seed or private key available",

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.NKeysError = exports.NKeysErrorCode = exports.Prefixes = exports.Prefix = exports.fromSeed = exports.fromPublic = exports.createServer = exports.createCluster = exports.createUser = exports.createAccount = exports.createOperator = exports.createPair = void 0;
exports.NKeysError = exports.NKeysErrorCode = exports.Prefixes = exports.Prefix = exports.fromSeed = exports.fromCurveSeed = exports.fromPublic = exports.createCurve = exports.createServer = exports.createCluster = exports.createUser = exports.createAccount = exports.createOperator = exports.createPair = void 0;
/*
* Copyright 2018-2023 The NATS Authors
* Copyright 2018-2024 The NATS Authors
* Licensed under the Apache License, Version 2.0 (the "License");

@@ -22,2 +22,3 @@ * you may not use this file except in compliance with the License.

const helper_1 = require("./helper");
const curve_1 = require("./curve");
/**

@@ -27,5 +28,8 @@ * @ignore

function createPair(prefix) {
const rawSeed = (0, helper_1.getEd25519Helper)().randomBytes(32);
const len = prefix === Prefix.Curve ? curve_1.curveKeyLen : 32;
const rawSeed = (0, helper_1.getEd25519Helper)().randomBytes(len);
let str = codec_1.Codec.encodeSeed(prefix, new Uint8Array(rawSeed));
return new kp_1.KP(str);
return prefix === Prefix.Curve
? new curve_1.CurveKP(new Uint8Array(rawSeed))
: new kp_1.KP(str);
}

@@ -72,2 +76,9 @@ exports.createPair = createPair;

/**
* @ignore
*/
function createCurve() {
return createPair(Prefix.Curve);
}
exports.createCurve = createCurve;
/**
* Creates a KeyPair from a specified public key

@@ -88,2 +99,13 @@ * @param {string} src of the public key in string format.

exports.fromPublic = fromPublic;
function fromCurveSeed(src) {
const sd = codec_1.Codec.decodeSeed(src);
if (sd.prefix !== Prefix.Curve) {
throw new NKeysError(NKeysErrorCode.InvalidCurveSeed);
}
if (sd.buf.byteLength !== curve_1.curveKeyLen) {
throw new NKeysError(NKeysErrorCode.InvalidSeedLen);
}
return new curve_1.CurveKP(sd.buf);
}
exports.fromCurveSeed = fromCurveSeed;
/**

@@ -96,4 +118,7 @@ * Creates a KeyPair from a specified seed.

function fromSeed(src) {
codec_1.Codec.decodeSeed(src);
// if we are here it decoded
const sd = codec_1.Codec.decodeSeed(src);
// if we are here it decoded properly
if (sd.prefix === Prefix.Curve) {
return fromCurveSeed(src);
}
return new kp_1.KP(src);

@@ -122,2 +147,3 @@ }

Prefix[Prefix["User"] = 160] = "User";
Prefix[Prefix["Curve"] = 184] = "Curve";
})(Prefix || (exports.Prefix = Prefix = {}));

@@ -133,3 +159,4 @@ /**

prefix == Prefix.Account ||
prefix == Prefix.User;
prefix == Prefix.User ||
prefix == Prefix.Curve;
}

@@ -139,3 +166,3 @@ static startsWithValidPrefix(s) {

return c == "S" || c == "P" || c == "O" || c == "N" || c == "C" ||
c == "A" || c == "U";
c == "A" || c == "U" || c == "X";
}

@@ -162,2 +189,4 @@ static isValidPrefix(prefix) {

return Prefix.User;
case Prefix.Curve:
return Prefix.Curve;
default:

@@ -179,4 +208,9 @@ return Prefix.Unknown;

NKeysErrorCode["InvalidSeed"] = "nkeys: invalid seed";
NKeysErrorCode["InvalidCurveSeed"] = "nkeys: invalid curve seed";
NKeysErrorCode["InvalidCurveKey"] = "nkeys: not a valid curve key";
NKeysErrorCode["InvalidCurveOperation"] = "nkeys: curve key is not valid for sign/verify";
NKeysErrorCode["InvalidNKeyOperation"] = "keys: only curve key can seal/open";
NKeysErrorCode["InvalidEncoding"] = "nkeys: invalid encoded key";
NKeysErrorCode["InvalidSignature"] = "nkeys: signature verification failed";
NKeysErrorCode["InvalidRecipient"] = "nkeys: not a valid recipient public curve key";
NKeysErrorCode["InvalidEncrypted"] = "nkeys: encrypted input is not valid";
NKeysErrorCode["CannotSign"] = "nkeys: cannot sign, no private key available";

@@ -183,0 +217,0 @@ NKeysErrorCode["PublicKeyOnly"] = "nkeys: no seed or private key available";

@@ -14,2 +14,4 @@ import { KeyPair } from "./nkeys";

clear(): void;
seal(input: Uint8Array, recipient: string, nonce?: Uint8Array): Uint8Array;
open(message: Uint8Array, sender: string): Uint8Array | null;
}
"use strict";
/*
* Copyright 2018-2020 The NATS Authors
* Copyright 2018-2024 The NATS Authors
* Licensed under the Apache License, Version 2.0 (the "License");

@@ -66,3 +66,9 @@ * you may not use this file except in compliance with the License.

}
seal(input, recipient, nonce) {
throw new nkeys_1.NKeysError(nkeys_1.NKeysErrorCode.InvalidNKeyOperation);
}
open(message, sender) {
throw new nkeys_1.NKeysError(nkeys_1.NKeysErrorCode.InvalidNKeyOperation);
}
}
exports.PublicKey = PublicKey;
{
"name": "nkeys.js",
"version": "1.0.6-1",
"version": "1.1.0",
"description": "A public-key signature system based on Ed25519 for the NATS ecosystem in javascript",

@@ -9,9 +9,10 @@ "main": "lib/index.js",

"init": "mkdir -p build",
"clean": "rm -Rf build/ lib/ nkeys.d.ts nkeys.mjs",
"clean": "rm -Rf build/ lib/ nkeys.d.ts nkeys.mjs ./coverage",
"fmt": "deno fmt src/ examples/ modules/ test/ node_test/",
"cjs": "deno run --allow-all bin/cjs-fix-imports.ts -o build/ src/ modules/cjs/ node_test/",
"generate": "deno run -A --unstable ./bin/tweetnacl-esm.ts",
"generate": "deno run -A ./bin/tweetnacl-esm.ts",
"stage": "npm run init && npm run cjs && npm run generate && tsc",
"prepare": "npm run stage && npm run generate && deno bundle modules/esm/mod.ts nkeys.mjs && tsc",
"test": "npm run prepare && ava --verbose && deno test -A --unstable test/",
"test": "npm run prepare && ava --verbose && deno test -A test/",
"cover": "npm run clean && npm run prepare && deno test --coverage=coverage -A test/ && deno coverage ./coverage --lcov > ./coverage/out.lcov && genhtml -o ./coverage/html ./coverage/out.lcov && open ./coverage/html/index.html",
"doc": "npm run clean && rm -Rf docs && npm run stage && node_modules/.bin/typedoc --out docs/ && touch ./docs/.nojekyll",

@@ -40,6 +41,6 @@ "bump-qualifier": "npm version prerelease --no-commit-hooks --no-git-tag-version",

"devDependencies": {
"@types/node": "^20.8.x",
"ava": "^5.2.x",
"typedoc": "^0.25.x",
"typescript": "^5.2.x"
"@types/node": "^20.11.x",
"ava": "^6.1.x",
"typedoc": "^0.25.8",
"typescript": "^5.3.3"
},

@@ -46,0 +47,0 @@ "ava": {

Sorry, the diff of this file is not supported yet

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