I have rust code outside canister running using axum server.
Which has generated secp256k1 key pair.
I want to pass its public key on the javascript frontend to create delegated identity.
In the first step, I’m trying to create DelegationChain in javascript by using Signed Delegation generated on Rust server.
However it fails to load public key.
Rust code looks like this:
// client_pem is created using secp256k1 SecretKey
// similar to shown here : https://github.com/dfinity/sdk/blob/95d2e707d06e0087fb5bf2b187d5014b3b4e908f/src/dfx-core/src/identity/identity_manager.rs#L804
let client_identity =
Secp256k1Identity::from_pem(client_pem.private_key.as_bytes()).unwrap();
let delegation = Delegation {
pubkey: client_identity.public_key.as_bytes().to_vec(),
expiration,
targets: None,
};
let signature = client_identity.sign_delegation(&delegation).unwrap();
let signed_delegation = SignedDelegation {
delegation,
signature: signature.signature.unwrap(),
};
let client_pubkey: Vec<u8> = client_identity.public_key().unwrap();
Rust API returns signed_delegation & client_pubkey to JS frontend.
I found below implementation in buffer.ts which I used further in code.
function toHexString(bytes) {
return new Uint8Array(bytes).reduce((str, byte) => str + byte.toString(16).padStart(2, '0'), '');
}
I have access to public_key() or to_sec1_der() methods for ic_agent::Identity objects in Rust. which returns Vec from rust. to_sec1_der() must be der encoded key, while public_key may not. Please correct my understanding. I used to_sec1_der() below. However using public_key() (which has different u8 array) also gives same error.
the values looks like these:
JsonnableDelegationChain Object after parsing on frontend looks like this: