( agent: HttpAgent, canisterId: Principal, )
| 432 | }; |
| 433 | |
| 434 | export 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 | |
| 468 | export async function fetchCanisterControllers( |
| 469 | agent: HttpAgent, |
no test coverage detected