Skip to content

Commit

Permalink
more cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
krpeacock committed Sep 29, 2023
1 parent ca8a33f commit 6cad1c3
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 21 deletions.
14 changes: 0 additions & 14 deletions packages/agent/src/agent/http/http.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -811,17 +811,3 @@ describe('default host', () => {
}
});
});

describe('fetchSubnetKeys', () => {
it.skip('should fetch node keys on application canisters for mainnet.', async () => {
jest.useFakeTimers();
// const abbbb = (await import('isomorphic-fetch')).default;
// const agent = new HttpAgent({ fetch: abbbb, host: 'https://icp-api.io' });
// await agent.fetchRootKey();
// const subnetKeys = await agent.fetchSubnetKeys('erxue-5aaaa-aaaab-qaagq-cai'); //?
// const subnetKeys = await agent.fetchSubnetKeys('ryjl3-tyaaa-aaaaa-aaaba-cai'); //?

// docs bkyz2-fmaaa-aaaaa-qaaaq-cai
// docs system bnz7o-iuaaa-aaaaa-qaaaa-cai
});
});
12 changes: 8 additions & 4 deletions packages/agent/src/canisterStatus/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@
import { Principal } from '@dfinity/principal';
import { AgentError } from '../errors';
import { HttpAgent } from '../agent/http';
import { Certificate, CreateCertificateOptions, SubnetStatus } from '../certificate';
import {
Certificate,
CreateCertificateOptions,
SubnetStatus,
lookupResultToBuffer,
} from '../certificate';
import { toHex } from '../utils/buffer';
import * as Cbor from '../cbor';
import { decodeLeb128, decodeTime } from '../utils/leb';
Expand Down Expand Up @@ -116,7 +121,7 @@ export const request = async (options: {
} else {
return {
path: path,
data: cert.lookup(encodePath(path, canisterId)),
data: lookupResultToBuffer(cert.lookup(encodePath(path, canisterId))),
};
}
};
Expand All @@ -131,7 +136,7 @@ export const request = async (options: {
} else {
status.set(path.key, null);
}
} else if (!Array.isArray(data)) {
} else {
switch (path) {
case 'time': {
status.set(path, decodeTime(data));
Expand Down Expand Up @@ -181,7 +186,6 @@ export const request = async (options: {
}
}
} catch (error) {
error;
// Break on signature verification errors
if ((error as AgentError)?.message?.includes('Invalid certificate')) {
throw new AgentError((error as AgentError).message);
Expand Down
7 changes: 4 additions & 3 deletions packages/agent/src/certificate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ export class Certificate {
}

public lookup(path: Array<ArrayBuffer | string>): ArrayBuffer | undefined {
// constrain the type of the result, so that empty HashTree is undefined
return lookupResultToBuffer(lookup_path(path, this.cert.tree));
}

Expand Down Expand Up @@ -262,7 +263,7 @@ export class Certificate {
let sigVer = false;

const lookupTime = this.lookup(['time']);
if (!lookupTime || !(lookupTime instanceof ArrayBuffer)) {
if (!lookupTime) {
// Should never happen - time is always present in IC certificates
throw new CertificateVerificationError('Certificate does not contain a time');
}
Expand Down Expand Up @@ -316,7 +317,7 @@ export class Certificate {
});

const rangeLookup = cert.lookup(['subnet', d.subnet_id, 'canister_ranges']);
if (!rangeLookup || !(rangeLookup instanceof ArrayBuffer)) {
if (!rangeLookup) {
throw new CertificateVerificationError(
`Could not find canister ranges for subnet 0x${toHex(d.subnet_id)}`,
);
Expand All @@ -338,7 +339,7 @@ export class Certificate {
);
}
const publicKeyLookup = cert.lookup(['subnet', d.subnet_id, 'public_key']);
if (!publicKeyLookup || !(publicKeyLookup instanceof ArrayBuffer)) {
if (!publicKeyLookup) {
throw new Error(`Could not find subnet key for subnet 0x${toHex(d.subnet_id)}`);
}
return publicKeyLookup;
Expand Down

0 comments on commit 6cad1c3

Please sign in to comment.