Follow-up of Read+write canister wasm module metadata - #3 by peterparker
I try to query wasm metadata using agent-js and I do not understand what value of CustomPath
or Metadata
should be provided to agent-js because it seems that any combination just works out.
e.g given such metadata:
await spawn({
command: 'ic-wasm',
args: [
OUTPUT,
'-o',
OUTPUT,
'metadata',
'hello:world', // <-------- here hello:world === metadata key
'-d',
'"yolo"', // <-------- here value === yolo
'-v',
'public'
]
});
I try to request the medata as following:
const agent = new HttpAgent({
host: import.meta.env.VITE_HOST,
});
await agent.fetchRootKey();
const request = await CanisterStatus.request({
canisterId: Principal.from(import.meta.env.VITE_CANISTER_ID),
agent,
paths: [
{
kind: "metadata",
key: "",
path: "hello:world",
decodeStrategy: "utf-8",
},
],
});
console.log(request);
Above works out but also
{
key: "",
path: "hello:world",
decodeStrategy: "utf-8",
},
or even
{
kind: "metadata",
key: "whatever-this-does-not-matter",
path: "hello:world",
decodeStrategy: "utf-8",
},
So I’m curious what’s correct, what’s the key and what’s the path because unless I missed something it isn’t that obvious from the ts doc:
**
* Interface to define a custom path. Nested paths will be represented as individual buffers, and can be created from text using {@link TextEncoder}
*/
export interface CustomPath {
key: string;
path: ArrayBuffer[] | string;
decodeStrategy: 'cbor' | 'hex' | 'leb128' | 'utf-8' | 'raw';
}
/**
* Interface to request metadata from the icp:public or icp:private sections.
* Similar to {@link CustomPath}, but accepts a simple string argument.
* Private metadata will require the ${@link Identity} used by the ${@link HttpAgent} will need to be requested using an identity that controlls the canister.
*/
export interface MetaData {
kind: 'metadata';
key: string;
path: string | ArrayBuffer;
decodeStrategy: 'cbor' | 'hex' | 'leb128' | 'utf-8' | 'raw';
}