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

yggdrasil

Package Overview
Dependencies
Maintainers
1
Versions
18
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

yggdrasil - npm Package Compare versions

Comparing version 0.1.0 to 0.2.0

61

lib/index.js
/* jshint node: true */
"use strict";
'use strict';
var crypto = require('crypto');

@@ -11,3 +11,3 @@ var assert = require('assert');

var config = {
host : con.host || "https://authserver.mojang.com" //Allow for a custom auth server
host : con.host || 'https://authserver.mojang.com' //Allow for a custom auth server
};

@@ -17,4 +17,4 @@

headers: {
"User-Agent" : "node-yggdrasil/" + version,
"Content-Type" : "application/json"
'User-Agent' : 'node-yggdrasil/' + version,
'Content-Type' : 'application/json'
}

@@ -27,8 +27,7 @@ });

method: 'POST',
uri: config.host + "/" + path,
uri: config.host + '/' + path,
json: data
}, function (err, resp, body) {
if (body && body.error) {
var out = body.errorMessage;
cb(out);
cb(new Error(body.errorMessage));
} else {

@@ -52,7 +51,7 @@ cb(err, body);

options.agent = options.agent || "Minecraft";
options.agent = options.agent || 'Minecraft';
r._call('authenticate', {
agent : {
name: options.agent,
version : options.agent === "Minecraft" ? 1 : options.version
version : options.agent === 'Minecraft' ? 1 : options.version
},

@@ -78,6 +77,7 @@ username: options.user,

}, function (err, data) {
if (data.clientToken !== client) {
cb("clientToken assertion failed");
if (err) cb(err);
if (data && data.clientToken !== client) {
cb(new Error('clientToken assertion failed'));
} else {
cb(null, data.accessToken, data);
cb(err, data ? data.accessToken : null, data);
}

@@ -90,3 +90,3 @@ });

* @param {String} token Token to validate
* @param {Function} cb (is okay, error)
* @param {Function} cb (error)
*/

@@ -97,7 +97,3 @@ r.validate = function (token, cb) {

}, function (err, data) {
if (err) {
cb(false, err);
} else {
cb(true);
}
cb(err);
});

@@ -109,3 +105,3 @@ };

* @param {String} pass User's pass
* @param {Function} cb (worked, error)
* @param {Function} cb (error)
*/

@@ -117,7 +113,3 @@ r.signout = function (user, pass, cb) {

}, function (err, data) {
if (err) {
cb(false, err);
} else {
cb(true);
}
cb(err);
});

@@ -132,3 +124,3 @@ };

var config = {
host : con.host || "https://sessionserver.mojang.com" //Allow for a custom auth server
host : con.host || 'https://sessionserver.mojang.com' //Allow for a custom auth server
};

@@ -138,4 +130,4 @@

headers: {
"User-Agent" : "node-yggdrasil/" + version,
"Content-Type" : "application/json"
'User-Agent' : 'node-yggdrasil/' + version,
'Content-Type' : 'application/json'
}

@@ -148,8 +140,7 @@ });

method: 'POST',
uri: config.host + "/" + path,
uri: config.host + '/' + path,
json: data
}, function (err, resp, body) {
if (body && body.error) {
var out = body.errorMessage;
cb(out);
cb(new Error(body.errorMessage));
} else {

@@ -215,5 +206,5 @@ cb(err, body);

r._call('session/minecraft/join', {
"accessToken": token,
"selectedProfile": profile,
"serverId": r.mcHexDigest(crypto.createHash('sha1').update(serverid).update(sharedsecret).update(serverkey).digest())
'accessToken': token,
'selectedProfile': profile,
'serverId': r.mcHexDigest(crypto.createHash('sha1').update(serverid).update(sharedsecret).update(serverkey).digest())
}, function(err, data) {

@@ -242,6 +233,6 @@ cb(err, data);

cb(err, body);
} else if (body && body.hasOwnProperty("id")) { // Success
} else if (body && body.hasOwnProperty('id')) { // Success
cb(err, body);
} else {
cb(new Error("Failed to verify username!"));
cb(new Error('Failed to verify username!'));
}

@@ -248,0 +239,0 @@ });

{
"name": "yggdrasil",
"version": "0.1.0",
"version": "0.2.0",
"author": "Zeke Sonxx <zeke@zekesonxx.com>",

@@ -24,4 +24,4 @@ "description": "Mojang authentication (Yggdrasil) client",

"dependencies": {
"request": "~2.34.0",
"uuid": "~1.4.1"
"request": "~2.78.0",
"uuid": "~2.0.3"
},

@@ -28,0 +28,0 @@ "license": "MIT",

# yggdrasil
[![Build Status](http://img.shields.io/travis/zekesonxx/node-yggdrasil.svg)](https://travis-ci.org/zekesonxx/node-yggdrasil)
[![NPM Link](https://img.shields.io/npm/v/yggdrasil.svg?style=plastic)](https://www.npmjs.com/package/yggdrasil)
[![Build Status](http://img.shields.io/travis/zekesonxx/node-yggdrasil.svg?style=plastic)](https://travis-ci.org/zekesonxx/node-yggdrasil)

@@ -7,2 +8,5 @@ A Node.js client for doing requests to yggdrasil, the Mojang authentication system, used for Minecraft and Scrolls.

node-yggdrasil was originally made because I was messing around with trying to make a Minecraft server in JS. Never really got anywhere with it.
However, the folks over at [PrismarineJS](https://github.com/PrismarineJS/) have gotten quite far with it, and use this library in their project.
# Usage

@@ -32,6 +36,6 @@ $ npm install yggdrasil

//Validate an accessToken
ygg.validate(token, function(isvalid, err){});
ygg.validate(token, function(err){});
//Invalidate all accessTokens
ygg.signout(username, password, function(worked, err));
ygg.signout(username, password, function(err));
```

@@ -57,2 +61,2 @@

* [node-minecraft-protocol](https://github.com/PrismarineJS/node-minecraft-protocol), a Minecraft client and server in Node.js
* [prismarine-yggdrasil](https://github.com/PrismarineJS/prismarine-yggdrasil), another yggdrasil client that node-yggdrasil [will be replacing](https://github.com/PrismarineJS/prismarine-yggdrasil/issues/2).
* [prismarine-yggdrasil](https://github.com/PrismarineJS/prismarine-yggdrasil), another yggdrasil client that node-yggdrasil replaced (issue links: [prismarine-yggdrasil #2](https://github.com/PrismarineJS/prismarine-yggdrasil/issues/2), [node-minecraft-protocol #117](https://github.com/PrismarineJS/node-minecraft-protocol/issues/117)).

@@ -14,3 +14,3 @@ /* jshint node: true, expr: true */

cake: true,
username: "someone"
username: 'someone'
};

@@ -26,8 +26,9 @@ scope.post('/test', {}).reply(200, bsdata);

scope.post('/test2', {}).reply(200, {
error: "ThisBeAError",
errorMessage: "Yep, you failed."
error: 'ThisBeAError',
errorMessage: 'Yep, you failed.'
});
ygg._call('test2', {}, function (err, data) {
should(data).be.undefined;
err.should.equal("Yep, you failed.");
err.should.be.an.instanceOf(Error);
err.message.should.equal('Yep, you failed.');
done();

@@ -42,7 +43,7 @@ });

version: 1,
name: "Minecraft"
name: 'Minecraft'
},
username: "cake",
password: "hunter2",
clientToken: "bacon"
username: 'cake',
password: 'hunter2',
clientToken: 'bacon'
}).reply(200, {

@@ -52,5 +53,5 @@ worked: true

ygg.auth({
user: "cake",
pass: "hunter2",
token: "bacon"
user: 'cake',
pass: 'hunter2',
token: 'bacon'
}, function (err, data) {

@@ -67,11 +68,11 @@ data.should.eql({

scope.post('/refresh', {
accessToken: "bacon",
clientToken: "not bacon"
accessToken: 'bacon',
clientToken: 'not bacon'
}).reply(200, {
accessToken: "different bacon",
clientToken: "not bacon"
accessToken: 'different bacon',
clientToken: 'not bacon'
});
ygg.refresh("bacon", "not bacon", function (err, token) {
ygg.refresh('bacon', 'not bacon', function (err, token) {
should(err).be.undefined;
token.should.equal("different bacon");
token.should.equal('different bacon');
done();

@@ -82,11 +83,12 @@ });

scope.post('/refresh', {
accessToken: "bacon",
clientToken: "not bacon"
accessToken: 'bacon',
clientToken: 'not bacon'
}).reply(200, {
accessToken: "different bacon",
clientToken: "bacon"
accessToken: 'different bacon',
clientToken: 'bacon'
});
ygg.refresh("bacon", "not bacon", function (err, token) {
ygg.refresh('bacon', 'not bacon', function (err, token) {
should(token).be.undefined;
err.should.equal("clientToken assertion failed");
err.should.be.an.instanceOf(Error);
err.message.should.equal('clientToken assertion failed');
done();

@@ -97,8 +99,7 @@ });

describe ('validate', function () {
it ('should return true on valid response', function (done) {
it ('should return undefined on valid response', function (done) {
scope.post('/validate', {
accessToken: "a magical key"
accessToken: 'a magical key'
}).reply(200);
ygg.validate("a magical key", function (okay, err) {
okay.should.be.true;
ygg.validate('a magical key', function (err) {
should(err).be.undefined;

@@ -108,12 +109,12 @@ done();

});
it ('should return false on an error', function (done) {
it ('should return Error on error', function (done) {
scope.post('/validate', {
accessToken: "a magical key"
accessToken: 'a magical key'
}).reply(403, {
error: "UserEggError",
errorMessage: "User is an egg"
error: 'UserEggError',
errorMessage: 'User is an egg'
});
ygg.validate("a magical key", function (okay, err) {
okay.should.be.false;
err.should.equal("User is an egg");
ygg.validate('a magical key', function (err) {
err.should.be.an.instanceOf(Error);
err.message.should.equal('User is an egg');
done();

@@ -138,3 +139,3 @@ });

cake: true,
username: "someone"
username: 'someone'
};

@@ -150,8 +151,9 @@ sscope.post('/test', {}).reply(200, bsdata);

sscope.post('/test2', {}).reply(200, {
error: "ThisBeAError",
errorMessage: "Yep, you failed."
error: 'ThisBeAError',
errorMessage: 'Yep, you failed.'
});
yggserver._call('test2', {}, function (err, data) {
should(data).be.undefined;
err.should.equal("Yep, you failed.");
err.should.be.an.instanceOf(Error);
err.message.should.equal('Yep, you failed.');
done();

@@ -180,5 +182,5 @@ });

sscope.post('/session/minecraft/join', {
"accessToken": 'anAccessToken',
"selectedProfile": 'aSelectedProfile',
"serverId": '-af59e5b1d5d92e5c2c2776ed0e65e90be181f2a'
'accessToken': 'anAccessToken',
'selectedProfile': 'aSelectedProfile',
'serverId': '-af59e5b1d5d92e5c2c2776ed0e65e90be181f2a'
}).reply(200, {

@@ -188,3 +190,3 @@ worked: true

yggserver.join("anAccessToken", "aSelectedProfile", "cat", "cat", "cat", function (err, data) {
yggserver.join('anAccessToken', 'aSelectedProfile', 'cat', 'cat', 'cat', function (err, data) {
data.should.eql({

@@ -205,3 +207,3 @@ worked: true

yggserver.hasJoined("ausername", "cat", "cat", "cat", function (err, data) {
yggserver.hasJoined('ausername', 'cat', 'cat', 'cat', function (err, data) {
if (err) return done(err);

@@ -218,4 +220,4 @@ data.should.eql({

yggserver.hasJoined("ausername", "cat", "cat", "cat", function (err, data) {
err.should.be.an.Error;
yggserver.hasJoined('ausername', 'cat', 'cat', 'cat', function (err, data) {
err.should.be.an.instanceOf(Error);
done();

@@ -222,0 +224,0 @@ });

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