Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit ac1ae8d
Showing
13 changed files
with
798 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
node_modules |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{ | ||
"curly": true, | ||
"eqeqeq": true, | ||
"immed": true, | ||
"latedef": "nofunc", | ||
"newcap": true, | ||
"noarg": true, | ||
"sub": true, | ||
"undef": true, | ||
"unused": true, | ||
"boss": true, | ||
"eqnull": true, | ||
"node": true, | ||
"predef": ["describe", "it", "before", "beforeEach", "after", "afterEach", "module"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
language: node_js | ||
node_js: | ||
- "0.10" | ||
- "0.8" | ||
before_install: | ||
- "npm install -g grunt-cli" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
'use strict'; | ||
|
||
module.exports = function(grunt) { | ||
|
||
grunt.initConfig({ | ||
pkg: grunt.file.readJSON('package.json'), | ||
jshint: { | ||
all: ['src/**/*.js', 'test/**/*.js', 'Gruntfile.js'], | ||
checkstyle: 'checkstyle.xml', | ||
options: { | ||
jshintrc: '.jshintrc' | ||
}, | ||
gruntfile: { | ||
src: 'Gruntfile.js' | ||
}, | ||
src: { | ||
src: ['src/**/*.js'] | ||
}, | ||
test: { | ||
src: ['test/**/*.js'] | ||
} | ||
}, | ||
simplemocha: { | ||
all: { src: 'test/**/*-test.js' }, | ||
options: { | ||
ui: 'bdd', | ||
reporter: 'spec' | ||
} | ||
} | ||
|
||
}); | ||
|
||
// task loading | ||
grunt.loadNpmTasks('grunt-contrib-jshint'); | ||
grunt.loadNpmTasks('grunt-simple-mocha'); | ||
|
||
// ci task | ||
grunt.registerTask('default', ['simplemocha', 'jshint:all']); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
Copyright (c) 2014 Nikolay Tsenkov | ||
|
||
Permission is hereby granted, free of charge, to any person | ||
obtaining a copy of this software and associated documentation | ||
files (the "Software"), to deal in the Software without | ||
restriction, including without limitation the rights to use, | ||
copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the | ||
Software is furnished to do so, subject to the following | ||
conditions: | ||
|
||
The above copyright notice and this permission notice shall be | ||
included in all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES | ||
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | ||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT | ||
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, | ||
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | ||
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR | ||
OTHER DEALINGS IN THE SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,192 @@ | ||
# license-key [![Build Status](https://secure.travis-ci.org/nicroto/license-key.png?branch=master)](http://travis-ci.org/nicroto/license-key) | ||
|
||
License-key generator for NodeJS. | ||
|
||
## Getting Started | ||
Install license-key with: | ||
```bash | ||
$ npm install license-key --save | ||
``` | ||
|
||
## Description | ||
NodeJS module for generation of license-keys. This module supports DSA and ECDSA keys (this is the current state-of-the-art, since it provides the same level of security as RSA, but in shorter keys). The generated license-key is intended as a copy-paste type of text, not to be rewritten letter-by-letter by the end-user. The serial number part of the license is encoded in base64 (usually people implement their own base32 scheme, but since there is no clear standard, and since this is a copy-paste solution - keys get smaller with base64, it is therefore the better solution). | ||
|
||
## Dependencies | ||
The module requires openssl. You can specify a custom path if you want to use a custom build/install, that isn't on the PATH. **Supported are versions starting from 1.0.1**. | ||
|
||
## Init | ||
The module exports the LicenseGenerator type, which is initialized with the **absolute** path to your private key, and optionally the **absolute** path to a custom build of OpenSSSL (otherwise it will try to use the one on the PATH if any): | ||
```javascript | ||
var pathUtils = require('path'), | ||
LicenseGenerator = require('license-key'); | ||
|
||
var lgen = new LicenseGenerator( { | ||
privateKeyPath: pathUtils.resolve( "custom/path/to/your/private/key" ), | ||
opensslPath: pathUtils.resolve( "custom/path/to/openssl" ) | ||
} ); | ||
``` | ||
|
||
## Generating Licenses | ||
Once you create an instance of the generator the default way of generating a key is: | ||
```javascript | ||
var signThis = "Nikolay Tsenkov"; | ||
lgen.generateLicense( { | ||
signThis: signThis | ||
}, function(license) { | ||
// ... | ||
} ); | ||
``` | ||
|
||
This will produce a license key, which uses the default template and will look similar to this: | ||
``` | ||
====BEGIN LICENSE==== | ||
Nikolay Tsenkov | ||
xxxxxxxxxxxxxxxxxxxxx | ||
=====END LICENSE===== | ||
``` | ||
|
||
Templates are standard mustache tempaltes. If the default tempalte is used, then the model bound the default tempalte has 2 default fields - name and serial. | ||
|
||
## Custom License templates | ||
You can create your own mustache template (this sounds weird :smile:). If you provide your own template, then the only field in the model data will be automatically added will be the produced serial. You need to specify the serial field in the template, or otherwise will get license with no serial. | ||
|
||
Here is a sample of a custom template: | ||
```javascript | ||
var signThis = "Nikolay Tsenkov", | ||
template = [ | ||
"====Custom Begin====", | ||
"Name: {{&name}}", | ||
"", | ||
"{{&serial}}", | ||
"=====Custom End=====" | ||
].join( "\n" ); | ||
lgen.generateLicense( { | ||
signThis: signThis, | ||
template: template | ||
}, function(license) { | ||
// ... | ||
} ); | ||
``` | ||
|
||
This will produce something like: | ||
|
||
|
||
``` | ||
====Custom Begin==== | ||
Name: Nikolay Tsenkov | ||
xxxxxxxxxxxxxxxxxxxxx | ||
=====Custom End===== | ||
``` | ||
|
||
As you can see, you don't specify the model and your ```name``` and ```serial``` fields are automatically mapped (they are the default fields). | ||
|
||
If you pass a model, though, then only serial is being dynamically added to it - it's up to you, what else you want and how you want to display it. | ||
|
||
Here is an example with a bit more data: | ||
```javascript | ||
var name = "Nikolay Tsenkov", | ||
email = "some@email.com", | ||
licenseMeta = "Quantity: 1", | ||
appMeta = "appVersion: 1", | ||
signThis = [ name, email, licenseMeta, appMeta ].join( " | " ), | ||
template = [ | ||
"====BEGIN LICENSE====", | ||
"{{&name}}", | ||
"{{&email}}", | ||
"{{&licenseMeta}}", | ||
"{{&appMeta}}", | ||
"{{&serial}}", | ||
"=====END LICENSE=====" | ||
].join( "\n" ); | ||
lgen.generateLicense( { | ||
signThis: signThis, | ||
template: template, | ||
model: { | ||
name: name, | ||
email: email, | ||
licenseMeta: licenseMeta, | ||
appMeta: appMeta | ||
} | ||
}, function(license) { | ||
// ... | ||
} ); | ||
``` | ||
|
||
As you can see, here you generate the license serial, from something that you don't display (check signThis). Here is the approximate result: | ||
``` | ||
====BEGIN LICENSE==== | ||
Nikolay Tsenkov | ||
some@email.com | ||
Quantity: 1 | ||
appVersion: 1 | ||
xxxxxxxxxxxxxxxxxxxxx | ||
=====END LICENSE===== | ||
``` | ||
|
||
## Custom serial formatting | ||
Since serial numbers are generally pretty big and messy strings, you might want to format the serial into pretty columns. You can do so, by passing a serialFormat function in the model: | ||
```javascript | ||
var name = "Nikolay Tsenkov", | ||
email = "some@email.com", | ||
licenseMeta = "Quantity: 1", | ||
appMeta = "appVersion: 1", | ||
signThis = [ name, email, licenseMeta, appMeta ].join( " | " ), | ||
template = [ | ||
"====BEGIN LICENSE====", | ||
"{{&name}}", | ||
"{{&email}}", | ||
"{{&licenseMeta}}", | ||
"{{&appMeta}}", | ||
"{{&serial}}", | ||
"=====END LICENSE=====" | ||
].join( "\n" ); | ||
lgen.generateLicense( { | ||
signThis: signThis, | ||
template: template, | ||
model: { | ||
name: name, | ||
email: email, | ||
licenseMeta: licenseMeta, | ||
appMeta: appMeta, | ||
serialFormat: function(serial) { | ||
var colLength = 4, | ||
numOfColPerRow = 4, | ||
length = serial.length, | ||
numberOfColumns = (length % colLength) === 0 ? length / colLength : Math.ceil( length / colLength ), | ||
regex = new RegExp( ".{1," + colLength + "}", "g" ), | ||
colData = serial.match( regex ), | ||
resultLines = []; | ||
while ( colData.length ) { | ||
var row = colData.splice( 0, numOfColPerRow ); | ||
resultLines.push( row.join( " " ) ); | ||
} | ||
return resultLines.join( "\n" ); | ||
} | ||
} | ||
}, function(license) { | ||
// ... | ||
} ); | ||
``` | ||
|
||
This should produce something like this: | ||
``` | ||
====BEGIN LICENSE==== | ||
Nikolay Tsenkov | ||
some@email.com | ||
Quantity: 1 | ||
appVersion: 1 | ||
xxxx xxxx xxxx xxxx | ||
xxxx xxxx xxxx xxxx | ||
=====END LICENSE===== | ||
``` | ||
|
||
## Contributing | ||
In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code using [Grunt](http://gruntjs.com/). | ||
|
||
## Release History | ||
- 0.1.0 | ||
|
||
## License | ||
Copyright (c) 2014 Nikolay Tsenkov | ||
Licensed under the MIT license. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#!/bin/bash | ||
|
||
$1 dgst -sign $2 <(echo -n "$3") | openssl enc -base64 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
{ | ||
"name": "license-key", | ||
"description": "License-key generator for NodeJS.", | ||
"version": "0.1.0", | ||
"homepage": "https://github.com/nicroto/license-key", | ||
"author": { | ||
"name": "Nikolay Tsenkov", | ||
"email": "nikolay@tsenkov.net", | ||
"url": "http://about.me/tsenkov" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "hhttps://github.com/nicroto/license-key.git" | ||
}, | ||
"bugs": { | ||
"url": "https://github.com/nicroto/license-key/issues" | ||
}, | ||
"licenses": [ | ||
{ | ||
"type": "MIT", | ||
"url": "https://github.com/nicroto/license-key/blob/master/LICENSE-MIT" | ||
} | ||
], | ||
"main": "src/generator", | ||
"engines": { | ||
"node": ">= 0.8.0" | ||
}, | ||
"scripts": { | ||
"test": "grunt" | ||
}, | ||
"dependencies": { | ||
"mustache": "~0.8.1", | ||
"semver": "~2.2.1" | ||
}, | ||
"devDependencies": { | ||
"grunt-contrib-jshint": "~0.6.4", | ||
"grunt": "~0.4.1", | ||
"grunt-simple-mocha": "~0.4.0", | ||
"mocha": "~1.13.0", | ||
"should": "~3.3.1" | ||
}, | ||
"keywords": [ | ||
"license", | ||
"generator", | ||
"serial", | ||
"number" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
====BEGIN LICENSE==== | ||
{{name}} | ||
{{serial}} | ||
=====END LICENSE===== |
Oops, something went wrong.