Adjust signature canonicalization to reflect the docs
This commit is contained in:
@@ -103,7 +103,7 @@ export function canonicalizeObject<T = unknown>(data: T): unknown {
|
||||
* @returns The canonical JSON string.
|
||||
*/
|
||||
export function canonicalize(data: unknown, timestamp: number, nonce: string): string {
|
||||
const body = canonicalizeObject(data)
|
||||
const body = JSON.stringify(canonicalizeObject(data))
|
||||
return JSON.stringify({
|
||||
timestamp,
|
||||
nonce,
|
||||
@@ -119,8 +119,9 @@ export function canonicalize(data: unknown, timestamp: number, nonce: string): s
|
||||
* @returns The signature.
|
||||
*/
|
||||
export function sign(data: unknown, timestamp: number, nonce: string, secretKey: string): string {
|
||||
const canned = canonicalize(data, timestamp, nonce)
|
||||
return createHmac('sha256', secretKey)
|
||||
.update(canonicalize(data, timestamp, nonce), 'utf8')
|
||||
.update(canned, 'utf8')
|
||||
.digest('hex')
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user