Skip to content
This repository has been archived by the owner on Feb 24, 2023. It is now read-only.

Commit

Permalink
Updated npm dependencies (#12)
Browse files Browse the repository at this point in the history
Changed test macro to match new ava api
Fixed `new Buffer()` deprecations to `Buffer.alloc()`
Updated travis
  • Loading branch information
aricart committed Mar 22, 2019
1 parent 4a0861d commit 2d9845d
Show file tree
Hide file tree
Showing 8 changed files with 1,256 additions and 4,809 deletions.
8 changes: 5 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,16 @@ language: node_js
sudo: false

node_js:
- "6"
- "8"
- "10"
- "11"

cache: npm

git:
depth: false

script:
- if [[ "$TRAVIS_NODE_VERSION" == 6 ]]; then npm test; fi
- if [[ "$TRAVIS_NODE_VERSION" == 8 ]]; then npm test; fi
- if [[ "$TRAVIS_NODE_VERSION" == 10 ]]; then npm test; npm run cover:coveralls; fi
- if [[ "$TRAVIS_NODE_VERSION" == 10 ]]; then npm test; fi
- if [[ "$TRAVIS_NODE_VERSION" == 11 ]]; then npm test; npm run cover:coveralls; fi
5,995 changes: 1,220 additions & 4,775 deletions package-lock.json

Large diffs are not rendered by default.

14 changes: 7 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ts-nkeys",
"version": "1.0.10",
"version": "1.0.12",
"description": "A public-key signature system based on Ed25519 for the NATS ecosystem in typescript for ts-nats and node-nats",
"main": "lib/nkeys.js",
"types": "lib/nkeys.d.ts",
Expand Down Expand Up @@ -32,17 +32,17 @@
"author": "The NATS Authors",
"license": "Apache-2.0",
"devDependencies": {
"@types/node": "^9.6.13",
"ava": "1.0.0-beta.8",
"coveralls": "^3.0.2",
"@types/node": "^9.6.46",
"ava": "^1.3.1",
"coveralls": "^3.0.3",
"dependency-check": "2.5.x",
"if-node-version": "^1.1.1",
"nyc": "^12.0.2",
"nyc": "^13.3.0",
"ts-node": "^6.0.3",
"typescript": "^3.0.3"
"typescript": "^3.3.4000"
},
"dependencies": {
"tweetnacl": "^1.0.0"
"tweetnacl": "^1.0.1"
},
"ava": {
"failFast": false,
Expand Down
4 changes: 2 additions & 2 deletions src/base32.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export class base32 {
let byte = 0;
let j = 0;
let a = new Uint8Array(src);
let out = new Buffer(a.byteLength * 5 / 8 | 0);
let out = Buffer.alloc(a.byteLength * 5 / 8 | 0);
for(let i=0; i < a.byteLength; i++) {
let v = String.fromCharCode(a[i]);
let vv = base32.alphabet.indexOf(v);
Expand All @@ -64,4 +64,4 @@ export class base32 {
}
return out.slice(0, j);
}
}
}
6 changes: 3 additions & 3 deletions src/codec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ export class Codec {
let cap = payloadOffset + payloadLen + checkLen;
let checkOffset = payloadOffset + payloadLen;

let raw = new Buffer(cap);
let raw = Buffer.alloc(cap);
// make the prefixes human readable when encoded
if (seed) {
let encodedPrefix = Codec._encodePrefix(Prefix.Seed, role);
Expand Down Expand Up @@ -130,7 +130,7 @@ export class Codec {
// bit manipulation to setup for base32 encoding which takes 5 bits at a time.
let b1 = kind | (role >> 5);
let b2 = (role & 31) << 3; // 31 = 00011111
return new Buffer([b1, b2]);
return Buffer.from([b1, b2]);
}

static _decodePrefix(raw: Buffer) : Uint8Array {
Expand All @@ -143,4 +143,4 @@ export class Codec {
a[1] = b2;
return a;
}
}
}
4 changes: 2 additions & 2 deletions src/nkeys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import {KP} from "./kp";
import {PublicKey} from "./public";
import {Codec} from "./codec";

export const VERSION = "1.0.10";
export const VERSION = "1.0.12";

export function createPair(prefix: Prefix): KeyPair {
let rawSeed = ed25519.randomBytes(32).buffer;
Expand Down Expand Up @@ -205,4 +205,4 @@ export class NKeysError extends Error {
this.code = code;
this.chainedError = chainedError;
}
}
}
32 changes: 16 additions & 16 deletions test/base32.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,29 +17,29 @@ import test, {ExecutionContext} from "ava";
import {base32} from "../src/base32";


function base32Macro(t: ExecutionContext , input: string, expected: string) {
function base32Macro(t: ExecutionContext , input: Buffer|string, expected: string) {
t.plan(2);

let enc = base32.encode(Buffer.from(input));
t.deepEqual(enc, Buffer.from(expected));

let dec = base32.decode(Buffer.from(expected))
let dec = base32.decode(Buffer.from(expected));
t.deepEqual(dec, Buffer.from(input))
}

// Tests copied from go library
// https://tools.ietf.org/html/rfc4648 and wikipedia ported
test('empty string', base32Macro, "", "", true);
test('f', base32Macro, Buffer.from("f"), "MY", true);
test('fo', base32Macro, Buffer.from("fo"), "MZXQ", true);
test('foo', base32Macro, Buffer.from("foo"), "MZXW6", true);
test('foob', base32Macro, Buffer.from("foob"), "MZXW6YQ", true);
test('fooba', base32Macro, Buffer.from("fooba"), "MZXW6YTB", true);
test('foobar', base32Macro, Buffer.from("foobar"), "MZXW6YTBOI", true);
test('sure.', base32Macro, Buffer.from("sure."), "ON2XEZJO", true);
test('sure', base32Macro, Buffer.from("sure"), "ON2XEZI", true);
test('sur', base32Macro, Buffer.from("sur"), "ON2XE", true);
test('su', base32Macro, Buffer.from("su"), "ON2Q", true);
test('leasure.', base32Macro, Buffer.from("leasure."), "NRSWC43VOJSS4", true);
test('easure.', base32Macro, Buffer.from("easure."), "MVQXG5LSMUXA", true);
test('asure.', base32Macro, Buffer.from("asure."), "MFZXK4TFFY", true);
test('empty string', base32Macro, "", "");
test('f', base32Macro, Buffer.from("f"), "MY");
test('fo', base32Macro, Buffer.from("fo"), "MZXQ");
test('foo', base32Macro, Buffer.from("foo"), "MZXW6");
test('foob', base32Macro, Buffer.from("foob"), "MZXW6YQ");
test('fooba', base32Macro, Buffer.from("fooba"), "MZXW6YTB");
test('foobar', base32Macro, Buffer.from("foobar"), "MZXW6YTBOI");
test('sure.', base32Macro, Buffer.from("sure."), "ON2XEZJO");
test('sure', base32Macro, Buffer.from("sure"), "ON2XEZI");
test('sur', base32Macro, Buffer.from("sur"), "ON2XE");
test('su', base32Macro, Buffer.from("su"), "ON2Q");
test('leasure.', base32Macro, Buffer.from("leasure."), "NRSWC43VOJSS4");
test('easure.', base32Macro, Buffer.from("easure."), "MVQXG5LSMUXA");
test('asure.', base32Macro, Buffer.from("asure."), "MFZXK4TFFY");
2 changes: 1 addition & 1 deletion test/integration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ test('encoded seed returns stable values albertor', (t) => {
let v = Codec.encodeSeed(Prefix.User, Buffer.from("albertoralbertoralbertoralbertor"));
t.is(v.toString('ascii'), data.seed);

var kp = fromSeed(v)
var kp = fromSeed(v);
t.is(kp.getSeed().toString('ascii'), data.seed, "seed");
t.is(kp.getPublicKey().toString('ascii'), data.public_key, "public key");
t.is(kp.getPrivateKey().toString('ascii'), data.private_key, "private key");
Expand Down

0 comments on commit 2d9845d

Please sign in to comment.