Skip to content

Commit

Permalink
fix: Switch to a class setup for the core methods
Browse files Browse the repository at this point in the history
  • Loading branch information
iainjreid committed Apr 18, 2020
1 parent ef6703d commit 9f7c1ba
Showing 1 changed file with 26 additions and 13 deletions.
39 changes: 26 additions & 13 deletions lib/sdk.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,21 +57,34 @@ export.exportKey = (key) => {
}

/**
* Generate a ticket for the required epoch.
*
* @param key {CryptoKey}
* @param timestamp {Number}
*
* @returns {Number}
* Class holding the core functionality of the Pat SDK
*/
export.createTicket = (key, timestamp) => {
// An ArrayBuffer representation of the timestamp
const _timestamp = (new TextEncoder()).encode(timestamp).buffer
export.PatSDK = class PatSDK {
/**
* Create an instance of the Pat SDK.
*
* @param key {CryptoKey}
*/
constructor(key) {
this.key = key
}

/**
* Generate a ticket for the required epoch.
*
* @param timestamp {Number}
*
* @returns {Number}
*/
createTicket(timestamp) {
// An ArrayBuffer representation of the timestamp
const _timestamp = (new TextEncoder()).encode(timestamp).buffer

return crypto.subtle.sign(keyOptions[0], key, _timestamp).then((key) => {
return (new Uint8Array(key)).reduce((acc, int) => {
return (acc + int) % 1000
return crypto.subtle.sign(keyOptions[0], this.key, _timestamp).then((hash) => {
return (new Uint8Array(hash)).reduce((acc, int) => {
return (acc + int) % 1000
})
})
})
}
}

0 comments on commit 9f7c1ba

Please sign in to comment.