mirror of
https://github.com/alexgo-io/stacks.js.git
synced 2026-04-29 09:45:50 +08:00
update package name to blockstack auth
This commit is contained in:
26
README.md
26
README.md
@@ -1,26 +1,24 @@
|
||||
# Blockchain Auth JS
|
||||
# Blockstack Auth JS
|
||||
|
||||
[](https://circleci.com/gh/blockstack/blockstack-auth-js/tree/master)
|
||||
[](https://www.npmjs.com/package/blockchain-auth)
|
||||
[](https://www.npmjs.com/package/blockchain-auth)
|
||||
[](https://www.npmjs.com/package/blockchain-auth)
|
||||
[](https://www.npmjs.com/package/blockstack-auth)
|
||||
[](https://www.npmjs.com/package/blockstack-auth)
|
||||
[](https://www.npmjs.com/package/blockstack-auth)
|
||||
[](http://slack.blockstack.org/)
|
||||
|
||||
A Blockchain ID authentication library written in node.js that supports generating, decoding and verifying auth request and auth response tokens.
|
||||
|
||||
[](https://github.com/blockstack/blockchain-id/wiki/Blockchain-Auth)
|
||||
Blockstack Auth is a Blockstack ID authentication library written in node.js that supports generating, decoding and verifying auth request and auth response tokens.
|
||||
|
||||
## Installation
|
||||
|
||||
```
|
||||
$ npm install blockchain-auth
|
||||
$ npm install blockstack-auth
|
||||
```
|
||||
|
||||
```js
|
||||
var AuthRequest = require('blockchain-auth').AuthRequest,
|
||||
AuthResponse = require('blockchain-auth').AuthResponse,
|
||||
verifyAuthMessage = require('blockchain-auth').verifyAuthMessage,
|
||||
decodeToken = require('blockchain-auth').decodeToken
|
||||
var AuthRequest = require('blockstack-auth').AuthRequest,
|
||||
AuthResponse = require('blockstack-auth').AuthResponse,
|
||||
verifyAuthMessage = require('blockstack-auth').verifyAuthMessage,
|
||||
decodeToken = require('blockstack-auth').decodeToken
|
||||
```
|
||||
|
||||
## Auth Requests
|
||||
@@ -54,7 +52,7 @@ var AuthRequest = require('blockchain-auth').AuthRequest,
|
||||
### Verifying Requests
|
||||
|
||||
```js
|
||||
verifyAuthMessage(authRequestToken, blockchainIdResolver, function(verified) {
|
||||
verifyAuthMessage(authRequestToken, blockstackResolver, function(verified) {
|
||||
console.log(verified)
|
||||
}, function(err) {
|
||||
console.log(err)
|
||||
@@ -96,7 +94,7 @@ verifyAuthMessage(authRequestToken, blockchainIdResolver, function(verified) {
|
||||
### Verifying Responses
|
||||
|
||||
```js
|
||||
verifyAuthMessage(authResponseToken, blockchainIdResolver, function(verified) {
|
||||
verifyAuthMessage(authResponseToken, blockstackResolver, function(verified) {
|
||||
console.log(verified)
|
||||
}, function(err) {
|
||||
console.log(err)
|
||||
|
||||
@@ -7,8 +7,8 @@ var TokenVerifier = require('jwt-js').TokenVerifier,
|
||||
decodeToken = require('jwt-js').decodeToken,
|
||||
PublicKeychain = require('keychain-manager').PublicKeychain
|
||||
|
||||
function verifyAuthInProfile(blockchainIDResolver, username, key, isKeychain, resolve, reject) {
|
||||
blockchainIDResolver([username], function(data) {
|
||||
function verifyAuthInProfile(blockstackResolver, username, key, isKeychain, resolve, reject) {
|
||||
blockstackResolver([username], function(data) {
|
||||
if (data === null || data === '') {
|
||||
resolve(false)
|
||||
}
|
||||
@@ -50,7 +50,7 @@ function verifyKeychainChild(publicKeychain, childPublicKey, chainPath, resolve,
|
||||
resolve(derivedChildPublicKey === childPublicKey)
|
||||
}
|
||||
|
||||
function verifyAuthMessage(token, blockchainIDResolver, resolve, reject) {
|
||||
function verifyAuthMessage(token, blockstackResolver, resolve, reject) {
|
||||
var decodedToken = decodeToken(token),
|
||||
payload = decodedToken.payload
|
||||
|
||||
@@ -95,7 +95,7 @@ function verifyAuthMessage(token, blockchainIDResolver, resolve, reject) {
|
||||
|
||||
if (!hasKeychain) {
|
||||
var verifyAuthInProfilePromise = new Promise(function(resolve, reject) {
|
||||
verifyAuthInProfile(blockchainIDResolver, username, publicKey, false, resolve, reject)
|
||||
verifyAuthInProfile(blockstackResolver, username, publicKey, false, resolve, reject)
|
||||
})
|
||||
|
||||
verifyAuthInProfilePromise.then(function(value) {
|
||||
@@ -111,7 +111,7 @@ function verifyAuthMessage(token, blockchainIDResolver, resolve, reject) {
|
||||
})
|
||||
|
||||
var verifyAuthInProfilePromise = new Promise(function(resolve, reject) {
|
||||
verifyAuthInProfile(blockchainIDResolver, username, publicKeychain, true, resolve, reject)
|
||||
verifyAuthInProfile(blockstackResolver, username, publicKeychain, true, resolve, reject)
|
||||
})
|
||||
|
||||
Promise.all([verifyKeychainChildPromise, verifyAuthInProfilePromise])
|
||||
|
||||
22
package.json
22
package.json
@@ -1,14 +1,14 @@
|
||||
{
|
||||
"name": "blockchain-auth",
|
||||
"version": "1.4.0",
|
||||
"description": "Blockchain ID Auth Library",
|
||||
"name": "blockstack-auth",
|
||||
"version": "0.1.0",
|
||||
"description": "Blockstack Auth Library",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"test": "node test.js"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/blockstack/blockchain-auth-js.git"
|
||||
"url": "git+https://github.com/blockstack/blockstack-auth-js.git"
|
||||
},
|
||||
"keywords": [
|
||||
"blockchain",
|
||||
@@ -30,18 +30,20 @@
|
||||
"sso",
|
||||
"crypto",
|
||||
"cryptography",
|
||||
"token"
|
||||
"token",
|
||||
"blockstack",
|
||||
"blockstack auth"
|
||||
],
|
||||
"author": {
|
||||
"name": "Halfmoon Labs, Inc.",
|
||||
"email": "hello@onename.com",
|
||||
"url": "https://onename.com"
|
||||
"name": "Blockstack Inc.",
|
||||
"email": "support@onename.com",
|
||||
"url": "https://blockstack.com"
|
||||
},
|
||||
"license": "MIT",
|
||||
"bugs": {
|
||||
"url": "https://github.com/blockstack/blockchain-auth-js/issues"
|
||||
"url": "https://github.com/blockstack/blockstack-auth-js/issues"
|
||||
},
|
||||
"homepage": "https://github.com/blockstack/blockchain-auth-js#readme",
|
||||
"homepage": "https://github.com/blockstack/blockstack-auth-js#readme",
|
||||
"dependencies": {
|
||||
"base64url": "^1.0.4",
|
||||
"ecdsa-sig-formatter": "^1.0.2",
|
||||
|
||||
28
test.js
28
test.js
@@ -10,10 +10,10 @@ var test = require('tape'),
|
||||
|
||||
var onenameResolver = new OnenameClient(process.env.ONENAME_APP_ID, process.env.ONENAME_APP_SECRET)
|
||||
|
||||
function testBlockchainIDResolver(blockchainids, resolve, reject) {
|
||||
if (blockchainids[0] === 'onename.id') {
|
||||
function testBlockstackResolver(blockstackIDs, resolve, reject) {
|
||||
if (blockstackIDs[0] === 'todo.app') {
|
||||
resolve({
|
||||
"onename.id": {
|
||||
"todo.app": {
|
||||
"profile": {
|
||||
"auth": [
|
||||
{
|
||||
@@ -23,7 +23,7 @@ function testBlockchainIDResolver(blockchainids, resolve, reject) {
|
||||
}
|
||||
}
|
||||
})
|
||||
} else if (blockchainids[0] === 'ryan.id') {
|
||||
} else if (blockstackIDs[0] === 'ryan.id') {
|
||||
resolve({
|
||||
"ryan.id": {
|
||||
"profile": {
|
||||
@@ -50,7 +50,7 @@ function testAuthRequest() {
|
||||
test('basicRequest', function(t) {
|
||||
t.plan(4)
|
||||
|
||||
var issuingBlockchainID = 'onename.id'
|
||||
var issuingBlockchainID = 'todo.app'
|
||||
|
||||
var authRequest = new AuthRequest(privateKey)
|
||||
|
||||
@@ -65,7 +65,7 @@ function testAuthRequest() {
|
||||
t.equal(typeof authRequestToken, 'string', 'token should be a string')
|
||||
t.equal(decodedAuthRequestToken.payload.issuer.username, issuingBlockchainID, 'token blockchain id should match the reference')
|
||||
|
||||
verifyAuthMessage(authRequestToken, testBlockchainIDResolver, function(verified) {
|
||||
verifyAuthMessage(authRequestToken, testBlockstackResolver, function(verified) {
|
||||
t.equal(verified, true, 'token should be verified')
|
||||
}, function(err) {
|
||||
console.log(err)
|
||||
@@ -75,14 +75,14 @@ function testAuthRequest() {
|
||||
test('advancedRequest', function(t) {
|
||||
t.plan(4)
|
||||
|
||||
var issuingBlockchainID = 'onename.id'
|
||||
var issuingBlockchainID = 'todo.app'
|
||||
|
||||
var authRequest = new AuthRequest(privateKey)
|
||||
|
||||
authRequest.setIssuer({
|
||||
username: issuingBlockchainID,
|
||||
appName: 'Onename',
|
||||
appDomain: 'onename.com'
|
||||
appName: 'Todo App',
|
||||
appDomain: 'todo.app'
|
||||
})
|
||||
authRequest.setProvisions([
|
||||
{ action: 'disclose', scope: 'username' },
|
||||
@@ -99,7 +99,7 @@ function testAuthRequest() {
|
||||
t.equal(typeof authRequestToken, 'string', 'token should be a string')
|
||||
t.equal(decodedAuthRequestToken.payload.issuer.username, issuingBlockchainID, 'token blockchain id should match the reference')
|
||||
|
||||
verifyAuthMessage(authRequestToken, testBlockchainIDResolver, function(verified) {
|
||||
verifyAuthMessage(authRequestToken, testBlockstackResolver, function(verified) {
|
||||
t.equal(verified, true, 'token should be verified')
|
||||
}, function(err) {
|
||||
console.log(err)
|
||||
@@ -151,7 +151,7 @@ function testAuthResponse() {
|
||||
t.equal(decodedAuthResponseToken.payload.issuer.publicKey, publicKeyHex, 'token public key hex should match the reference value')
|
||||
t.equal(decodedAuthResponseToken.payload.provisions[0].signature, challengeSignature, 'challenge signature should match the reference value')
|
||||
|
||||
verifyAuthMessage(authResponseToken, testBlockchainIDResolver, function(verified) {
|
||||
verifyAuthMessage(authResponseToken, testBlockstackResolver, function(verified) {
|
||||
t.equal(verified, true, 'token should be verified')
|
||||
}, function(err) {
|
||||
console.log(err)
|
||||
@@ -161,7 +161,7 @@ function testAuthResponse() {
|
||||
test('partiallyIdentifiedResponse', function(t) {
|
||||
t.plan(1)
|
||||
|
||||
verifyAuthMessage(partiallyIdentifiedToken, testBlockchainIDResolver, function(verified) {
|
||||
verifyAuthMessage(partiallyIdentifiedToken, testBlockstackResolver, function(verified) {
|
||||
t.equal(verified, false, 'token should be invalid')
|
||||
}, function(err) {
|
||||
console.log(err)
|
||||
@@ -179,7 +179,7 @@ function testAuthResponse() {
|
||||
var authResponseToken = authResponse.sign()
|
||||
t.ok(authResponseToken, 'token should have been created')
|
||||
|
||||
verifyAuthMessage(authResponseToken, testBlockchainIDResolver, function(verified) {
|
||||
verifyAuthMessage(authResponseToken, testBlockstackResolver, function(verified) {
|
||||
t.equal(verified, false, 'token should be invalid')
|
||||
}, function(err) {
|
||||
console.log(err)
|
||||
@@ -200,7 +200,7 @@ function testAuthResponse() {
|
||||
t.equal(typeof authResponseToken, 'string', 'token should be a string')
|
||||
t.equal(decodedAuthResponseToken.payload.issuer.publicKey, publicKeyHex, 'token public key hex should match the reference value')
|
||||
|
||||
verifyAuthMessage(authResponseToken, testBlockchainIDResolver, function(verified) {
|
||||
verifyAuthMessage(authResponseToken, testBlockstackResolver, function(verified) {
|
||||
t.equal(verified, true, 'token should be verified')
|
||||
}, function(err) {
|
||||
console.log(err)
|
||||
|
||||
Reference in New Issue
Block a user