tickets
All repositories: gitoria
2.0 KB
// The per-chat push destination and encrypted HMAC secret. Never returned through the API.import { env } from 'hl:proc'import { hkdfExtract, randomBytes, fromBase64, base64urlEncode, base64urlDecode, aes128gcmEncrypt, aes128gcmDecrypt } from 'hl:crypto'static pushUrlError = (url) => {if (url == '') { return null }if (hlTypeName(url) != 'String' || url.length > 500 || url.includes('?') || url.includes('#') || url.includes('@') || url.includes('\\')) { return 'invalid pushUrl' }allowed = env('TICKETS_PUSH_ALLOWED')if (allowed == null || allowed == '') { return 'pushUrl is not allowed' }for (entry of allowed.split(',')) {let base = entry.trim()while (base.endsWith('/')) { base = base.slice(0, base.length - 1) }prefix = base + '/api/push/'if ((base.startsWith('http://') || base.startsWith('https://')) && url.startsWith(prefix)) {chat = url.slice(prefix.length)if (chat == '') { return 'pushUrl needs a chat id' }let i = 0while (i < chat.length) {if (!'0123456789-'.includes(chat[i])) { return 'pushUrl chat id must contain only digits and hyphens' }i = i + 1}return null}}return 'pushUrl is not allowed'}static pushKey = () => {master = env('TICKETS_PUSH_KEY')if (master == null || master.length < 32) { return null }return hkdfExtract(toBytes(master), toBytes('tickets subscription secrets v1')).slice(0, 16)}static sealPushSecret = (secret, url) => {key = pushKey()if (key == null) { return null }nonce = fromBase64(randomBytes(12, 'base64'))cipher = aes128gcmEncrypt(key, nonce, toBytes(secret), toBytes(url))return { nonce = base64urlEncode(nonce) cipher = base64urlEncode(cipher) }}static pushSecret = (s) => {key = pushKey()if (key == null || s.secret == null) { return null }nonce = base64urlDecode(s.secret.nonce)cipher = base64urlDecode(s.secret.cipher)if (nonce == null || nonce.length != 12 || cipher == null) { return null }plain = aes128gcmDecrypt(key, nonce, cipher, toBytes(s.pushUrl))return plain == null ? null : plain.toString()}
Branches
Latest commits
- 5d144817Merge branch 'records-t40' into mainTickets
- 44ee6f06|||PR records: #43 #45 livemre
- b8fdeee9Merge branch 'p39-routes' into mainTickets
- a0187a0a|||PR Remove redundant route-order loopmre
- 369e4b9cMerge branch 'k40-lists' into mainTickets
- 9af8e780|||PR Use keyed list mutations for live ticket updatesmre
- 610d8e8aMerge branch 'records-t39' into mainTickets
- 32bcdf24|||PR records: GO P39 K40mre
- 4123c6d1Merge branch 'records-t38' into mainTickets
- cd3641a1|||PR records: day72 deploy live, tickets closedmre
- 7d44d852Merge branch 'records-t37' into mainTickets
- 926f7061|||PR records: merges, D36 deploymre
- bf58534eMerge branch 'l33-final' into mainTickets
- 759a9ac3|||PR thin login (tickets#46, #45): merge main, route entry cleanupmre
- 239436d8Merge remote-tracking branch 'origin/main' into l33-finalmre
- 5822cb3aMerge branch 'o34-clean' into mainTickets
- 0870653c|||PR offline note from __hlOnline, no polling (tickets#41)mre
- 14cf96b4Merge branch 'records-t36' into mainTickets
- 07749fa1|||PR records: day72 + #40 mergedmre
- ecd7e226|||PR Consolidate login and move handler logic into topic libraries (partial)mre