Skip to content

Instantly share code, notes, and snippets.

@christiansmith
Last active May 20, 2017 19:41
Show Gist options
  • Save christiansmith/dbc1cad3ffa8994cd58176e7b574aab4 to your computer and use it in GitHub Desktop.
Save christiansmith/dbc1cad3ffa8994cd58176e7b574aab4 to your computer and use it in GitHub Desktop.
// VerifiedAddress.js
const { JWD, JWDSchema } = require('@trust/jose')

let VerifiedAddressSchema = JWDSchema.extend({
  properties: {
    payload: {
      address: {
        type: 'string',
        pattern: someRegExp
      }
    }
  }
})

class VerifiedAddress extends JWD {
  static get schema () {
    return VerifiedAddressSchema
  }
}

module.exports = VerifiedAddress
const VerifiedAddress = require('./VerifiedAddress')

VerifiedAddress.sign({
  payload: {
    sub: 'userid'
    address: '123 Main Street\nCambridge, MA 02139',
    iat: Math.floor(Date.now() / 1000),
    exp: Math.floor(Date.now() / 1000) + (60 * 60 * 24 * 365) // expire in 1 year
  },
  signatures: [
    {
      protected: { alg: 'RS256' },
      cryptoKey: privateCryptoKey
    }
  ]
})
.then(jwd => {
  // jwd is a signed document
})
{
      "payload": {
        "uuid": "1fc4d4b2-5d6d-40ff-95ed-8af13296450f",
        "uri": "https://localhost:3000/.../1fc4d4b2-5d6d-40ff-95ed-8af13296450f",
        "title": "Some Query",
        "description": "All your data belong to us",
        "version": "0.0.0",
        "price": 123,
        "lang": "application/sql",
        "exec": "SELECT * FROM FOO"
      },
      "signatures": [
        {
          "protected": {
            "alg": "RS256",
            "kid": "hdH5_sMdyzI",
            "jku": "https://localhost:3000/jwks"
          },
          "signature": "FveuwtVkkEAXBsAm37OzmczOPoN68V3sNt0pD2Vv4UnHTaf-D9uzE3nXVnn1yeWbGyeuvB5uZg74MiuOx3v_1iv27Usp5uV2TRoCILt76MfvBL4QoA1bKYc2juncz-K6amYXxilKs8O70uQ2GJe9hAS9HC8h9fLbTy5sbjh3_iOk1aiO8FjNTfRrSlTg2oioteasDDy2q5QJZ7EYi_1bxhodJKSXErL45SPenD_nrIz1VzmnRYcf8so6wLPtuNi_1FCVxLxQG2hJ1VI9_qNkMV7gmZPdNhAWolZWXPmP0SPW-AwsrUQT6EQRXsuSYPMbbJYW8m8f4UcolMyWkdSoWw"
        }
      ]
    },
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment