Open ByronBecker opened 5 months ago
Describe the bug Previously, in a NodeJS enviroment calling Ed25519KeyIdentity.fromSecretKey() with a key generated from dfx worked.
Ed25519KeyIdentity.fromSecretKey()
After bumping agentJS from ^0.15.3 to ^1.1.1, I now receive the following error.
^0.15.3
^1.1.1
<path_to_my_project>/node_modules/@noble/curves/src/abstract/utils.ts:134 throw new Error(`${title} expected ${expectedLength} bytes, got ${len}`); ^ Error: private key expected 32 bytes, got 64 at ensureBytes (<path_to_my_project>/node_modules/@noble/curves/src/abstract/utils.ts:134:11) at getExtendedPublicKey (<path_to_my_project>node_modules/@noble/curves/src/abstract/edwards.ts:421:22) at Object.getPublicKey (<path_to_my_project>/node_modules/@noble/curves/src/abstract/edwards.ts:435:12) at Function.fromSecretKey (<path_to_my_project>/node_modules/@dfinity/identity/src/identity/ed25519.ts:160:31) at identityFromPemFile (<path_to_my_project>/scripts/utils.ts:12:29) ...
Where the code for forming the identity from the pem file looks like this:
// utils.ts import { Ed25519KeyIdentity } from "@dfinity/identity"; import { readFileSync } from "fs-extra"; const pemFile = require("pem-file"); export function identityFromPemFile(pemFilePath: string): Ed25519KeyIdentity { const rawKey = readFileSync(pemFilePath).toString(); const buf = pemFile.decode(rawKey); if (buf.length !== 85) { throw new Error(`expecting byte length 85 but got ${buf.length}`); } const secretKey = Buffer.concat([buf.slice(16, 48), buf.slice(53, 85)]); return Ed25519KeyIdentity.fromSecretKey(secretKey); } // Example usage const identity = identityFromPemFile(<path_to_your_key);
I see that in the 0.20.0 Release Notes you have
this change replaces the package tweetnacl with @noble/curves for Ed25519 curve signatures and validation.
To Reproduce Steps to reproduce the behavior:
utils.ts
Expected behavior Ed25519KeyIdentity.fromSecretKey() should not behave differently between 0.15.3 and agent-js >= 0.20.0
Desktop (please complete the following information):
@krpeacock
For anyone else that runs into this issue, this solution fixed the error for me.
https://forum.dfinity.org/t/using-dfinity-agent-in-node-js/6169/69
Describe the bug Previously, in a NodeJS enviroment calling
Ed25519KeyIdentity.fromSecretKey()
with a key generated from dfx worked.After bumping agentJS from
^0.15.3
to^1.1.1
, I now receive the following error.Where the code for forming the identity from the pem file looks like this:
I see that in the 0.20.0 Release Notes you have
To Reproduce Steps to reproduce the behavior:
utils.ts
above, with your identity file path subbed inExpected behavior
Ed25519KeyIdentity.fromSecretKey()
should not behave differently between 0.15.3 and agent-js >= 0.20.0Desktop (please complete the following information):