Replies: 1 comment 4 replies
-
|
The error means the hex string you've passed in privateKey is invalid. It probably has some weird non-hex characters (hex is 0-9 a-f), or is not padded (abcdef vs 0abcdef). |
Beta Was this translation helpful? Give feedback.
4 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Am making use of the orderly api for authentication which uses the noble/ed25519 library for signing private keys but everytime i run the code the noble/ed25519 returns this error "hex invalid" I've tried with the node web crypto for generating ed25519 keys still returns the same error, please is there a fix for this?
Here's the error:
Here's the code below:
import { getPublicKeyAsync, signAsync } from '@noble/ed25519';
import { encodeBase58 } from 'ethers';
export async function signAndSendRequest(
orderlyAccountId: string,
privateKey: Uint8Array | string,
input: URL | string,
init?: RequestInit | undefined
): Promise {
const timestamp = Date.now();
const encoder = new TextEncoder();
const url = new URL(input);
let message =
${String(timestamp)}${init?.method ?? 'GET'}${url.pathname}${url.search};if (init?.body) {
message += init.body;
}
const orderlySignature = await signAsync(encoder.encode(message), privateKey);
return fetch(input, {
headers: {
'Content-Type':
init?.method !== 'GET' && init?.method !== 'DELETE'
? 'application/json'
: 'application/x-www-form-urlencoded',
'orderly-timestamp': String(timestamp),
'orderly-account-id': orderlyAccountId,
'orderly-key':
ed25519:${encodeBase58(await getPublicKeyAsync(privateKey))},'orderly-signature': Buffer.from(orderlySignature).toString('base64url'),
...(init?.headers ?? {})
},
...(init ?? {})
});
}
Beta Was this translation helpful? Give feedback.
All reactions