JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 83
  • Score
    100M100P100Q13130F
  • License MIT

Blockchain ID Auth Library

Package Exports

  • blockchain-auth

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (blockchain-auth) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

Blockchain Auth JS

CircleCI npm Slack

A Blockchain ID authentication library written in node.js that supports generating, decoding and verifying auth request and auth response tokens.

Read the Wiki

Getting Started

$ npm install blockchain-auth
var blockchainAuth = require('blockchain-auth'),
    AuthRequest = blockchainAuth.AuthRequest,
    AuthResponse = blockchainAuth.AuthResponse

Auth Requests

Request Format

{
    "header": {
        "typ": "JWT",
        "alg": "ES256"
    },
    "payload": {
        "issuedAt":"1440624435.28",
        "challenge":"8befe9e5-db3a-408a-aaae-c41c1c8eee55",
        "permissions":["blockchainid"],
        "issuer": {
            "publicKey":"0231e4873b5569c5811b4849cf1797f2bff3dab358b07416aa7a9af638f7182ca3",
            "domain":"onename.com"
        }
    },
    "signature": "MEUCIQDzUaSrgTR_tTpNSVcitKYvYWd3bc3uylMe3xCfo-QclQIgDLN1hgXSyqiEk0AGQ21XB2wzuqrotTmE_yN3pn4f_38"
}

Signing Requests

var authRequest = new AuthRequest(privateKeyHex, publicKeyHex, issuingDomain, permissions),
    authRequestToken = authRequest.token(),
    decodedAuthRequestToken = authRequest.decode()

Verifying Requests

AuthRequest.verify(authRequestToken, resolver, function(err, verified) {
    console.log(verified)
})

Auth Responses

Response Format

{
    "header": {
        "typ": "JWT",
        "alg": "ES256"
    },
    "payload": {
        "issuedAt": "1440713414.85",
        "challenge": "7cd9ed5e-bb0e-49ea-a323-f28bde3a0549",
        "issuer": {
            "publicKey": "03fdd57adec3d438ea237fe46b33ee1e016eda6b585c3e27ea66686c2ea5358479",
            "blockchainid": "ryan",
            "publicKeychain": "xpub661MyMwAqRbcFQVrQr4Q4kPjaP4JjWaf39fBVKjPdK6oGBayE46GAmKzo5UDPQdLSM9DufZiP8eauy56XNuHicBySvZp7J5wsyQVpi2axzZ",
            "chainPath": "bd62885ec3f0e3838043115f4ce25eedd22cc86711803fb0c19601eeef185e39"
        }
    },
    "signature": "MEUCIQDzUaSrgTR_tTpNSVcitKYvYWd3bc3uylMe3xCfo-QclQIgDLN1hgXSyqiEk0AGQ21XB2wzuqrotTmE_yN3pn4f_38"
}

Signing Responses

var authResponse = new AuthResponse(privateKeyHex, publicKeyHex, challenge, blockchainid, publicKeychain, chainPath),
    authResponseToken = authResponse.token(),
    decodedAuthResponseToken = authResponse.decode()

Signing Anonymous Responses

var authResponse = new AuthResponse(privateKeyHex, publicKeyHex, challenge)

Verifying Responses

AuthResponse.verify(authResponseToken, resolver, function(err, verified) {
})