Invalid value for '--specified-id <PRINCIPAL>': Text is too long

I’m writing property tests and getting this error:

error: invalid value 'deffl-liaaa-aaaaa-aaaaa-aaaaa-aaaaa-aaaaa-aaaaa-aaaaa-aaaaa-aaaaa-aaa' for '--specified-id <PRINCIPAL>': Text is too long.

I’m generating random bytes of length 32 and doing Principal.fromUint8Array(bytes);. Then I’m trying to deploy a canister with that princpal’s string representation like this:

execSync(
    `dfx deploy canister --specified-id ${canisterIdText}`
);

The principal above is a valid principal is it not? Why doesn’t the command line allow this to be done then?

1 Like

A principal should be less than 63 characters including with the hyphens. In this case, it is too long.

A principal should be a byte array. Therefore, you may need to convert the bytes to an Uint8Array?

const newArray = new Uint8Array(bytes)
const principal = Principal.fromUint8Array(new array)
1 Like

This is strange…but I am using Principal from @dfinity/principal and passing in a 32-byte Uint8Array, there is nothing going wrong there it is giving me that final string.

How is @dfinity/principal giving me an incorrect string? Wouldn’t it throw?

1 Like

Thank you for the clarification. We’ll take a look!

Compared to the Rust SDK, agent-js doesn’t seem to have a length check.

Here’s how the spec defines a principal:

As far as most uses of the IC are concerned they are opaque binary blobs with a length between 0 and 29 bytes

@anon74414410 can you maybe add a length check to Principal.fromUint8Array?

1 Like