Merge branch 'main' of gitlab.com:skyrainstudioindonesia-group/vega-cloud
This commit is contained in:
@@ -103,7 +103,7 @@ export function canonicalizeObject<T = unknown>(data: T): unknown {
|
|||||||
* @returns The canonical JSON string.
|
* @returns The canonical JSON string.
|
||||||
*/
|
*/
|
||||||
export function canonicalize(data: unknown, timestamp: number, nonce: string): string {
|
export function canonicalize(data: unknown, timestamp: number, nonce: string): string {
|
||||||
const body = canonicalizeObject(data)
|
const body = JSON.stringify(canonicalizeObject(data))
|
||||||
return JSON.stringify({
|
return JSON.stringify({
|
||||||
timestamp,
|
timestamp,
|
||||||
nonce,
|
nonce,
|
||||||
@@ -119,8 +119,9 @@ export function canonicalize(data: unknown, timestamp: number, nonce: string): s
|
|||||||
* @returns The signature.
|
* @returns The signature.
|
||||||
*/
|
*/
|
||||||
export function sign(data: unknown, timestamp: number, nonce: string, secretKey: string): string {
|
export function sign(data: unknown, timestamp: number, nonce: string, secretKey: string): string {
|
||||||
|
const canned = canonicalize(data, timestamp, nonce)
|
||||||
return createHmac('sha256', secretKey)
|
return createHmac('sha256', secretKey)
|
||||||
.update(canonicalize(data, timestamp, nonce), 'utf8')
|
.update(canned, 'utf8')
|
||||||
.digest('hex')
|
.digest('hex')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ export const router = new Elysia({
|
|||||||
}
|
}
|
||||||
return result
|
return result
|
||||||
}, {
|
}, {
|
||||||
|
verifyKey: true,
|
||||||
body: deviceCommandBody,
|
body: deviceCommandBody,
|
||||||
response: deviceCommandResponseSchema,
|
response: deviceCommandResponseSchema,
|
||||||
detail: {
|
detail: {
|
||||||
@@ -49,6 +50,7 @@ export const router = new Elysia({
|
|||||||
return { status: 'internal_error', message: 'Server error' }
|
return { status: 'internal_error', message: 'Server error' }
|
||||||
}
|
}
|
||||||
}, {
|
}, {
|
||||||
|
verifyKey: true,
|
||||||
query: deviceQueryParams,
|
query: deviceQueryParams,
|
||||||
response: deviceQueryResponseSchema,
|
response: deviceQueryResponseSchema,
|
||||||
detail: {
|
detail: {
|
||||||
|
|||||||
Reference in New Issue
Block a user