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.
|
* @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')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user