MCPcopy Create free account
hub / github.com/dfinity/orbit / fetchCanisterModuleHash

Function fetchCanisterModuleHash

apps/wallet/src/utils/helper.utils.ts:434–466  ·  view source on GitHub ↗
(
  agent: HttpAgent,
  canisterId: Principal,
)

Source from the content-addressed store, hash-verified

432};
433
434export async function fetchCanisterModuleHash(
435 agent: HttpAgent,
436 canisterId: Principal,
437): Promise<string | null> {
438 const encoder = new TextEncoder();
439 const moduleHashPath: ArrayBuffer[] = [
440 encoder.encode('canister'),
441 canisterId.toUint8Array(),
442 encoder.encode('module_hash'),
443 ];
444
445 const state = await agent.readState(canisterId, {
446 paths: [moduleHashPath],
447 });
448
449 const certificate = await Certificate.create({
450 canisterId,
451 certificate: state.certificate,
452 rootKey: agent.rootKey!,
453 });
454
455 const moduleHash = certificate.lookup(moduleHashPath);
456
457 if (moduleHash.status !== LookupStatus.Found) {
458 return null;
459 }
460
461 if (!(moduleHash.value instanceof ArrayBuffer)) {
462 throw new Error('Module hash value is not an ArrayBuffer');
463 }
464
465 return arrayBufferToHex(moduleHash.value);
466}
467
468export async function fetchCanisterControllers(
469 agent: HttpAgent,

Callers 1

Calls 2

arrayBufferToHexFunction · 0.90
createMethod · 0.45

Tested by

no test coverage detected