What type of topic is this?
Support
Hey all.
Here is my code, which doesn’t work:
import { AuthClient } from "https://cdn.jsdelivr.net/npm/@dfinity/auth-client@1.3.0/+esm"; import { HttpAgent } from "https://cdn.jsdelivr.net/npm/@dfinity/agent@1.3.0/+esm"; const ICPauthClient = await AuthClient.create(); window.ICPauthClient = ICPauthClient import isomorphicFetch from 'https://cdn.jsdelivr.net/npm/isomorphic-fetch@3.0.0/+esm' const host = 'local' === 'local' ? 'http://127.0.0.1:4943' : 'https://icp-api.io'; const ICPagent = new HttpAgent({ isomorphicFetch, host }); //isomorphicFetch, host, fetchOptions }); console.log("ICPagent " + JSON.stringify(ICPagent)) window.ICPagent = ICPagent const get_counter = await window.ICPagent.query( 'bd3sg-teaaa-aaaaa-qaaba-cai', { methodName: 'get_counter', arg: [], }, ) console.log("get_counter " + JSON.stringify(get_counter))
error:
index.ts:230 Uncaught Error: Invalid certificate: Signature verification failed
at index.ts:230:17
at async Promise.all (testNewChainsConnection/index 0)
at async fe (index.ts:248:3)
at async jt.fetchSubnetKeys (index.ts:994:11)
at async index.ts:699:11
at async Promise.all (testNewChainsConnection/index 1)
at async jt.query (index.ts:707:19)
at async testNewChainsConnection/:32:27
canisters runs locally:
URLs:
Backend canister via Candid interface:
factory: http://127.0.0.1:4943/?canisterId=bd3sg-teaaa-aaaaa-qaaba-cai&id=bkyz2-fmaaa-aaaaa-qaaaq-cai
icp_ledger_canister: http://127.0.0.1:4943/?canisterId=bd3sg-teaaa-aaaaa-qaaba-cai&id=ryjl3-tyaaa-aaaaa-aaaba-cai
internet_identity: http://127.0.0.1:4943/?canisterId=bd3sg-teaaa-aaaaa-qaaba-cai&id=rdmx6-jaaaa-aaaaa-aaadq-cai
motodex: http://127.0.0.1:4943/?canisterId=bd3sg-teaaa-aaaaa-qaaba-cai&id=be2us-64aaa-aaaaa-qaabq-cai
and working well with API http://127.0.0.1:4943/?canisterId=bd3sg-teaaa-aaaaa-qaaba-cai&id=be2us-64aaa-aaaaa-qaabq-cai#get_counter
I try to call same function with approved identity:
window.ICPauthClient.login({
// 7 days in nanoseconds
maxTimeToLive: BigInt(7 * 24 * 60 * 60 * 1000 * 1000 * 1000),
onSuccess: async () => {
console.log(“success”)
const identity = await window.ICPauthClient.getIdentity();
console.log("identity " + JSON.stringify(identity))
await window.ICPagent.replaceIdentity(await identity)
const get_counter = await window.ICPagent.query(
'bd3sg-teaaa-aaaaa-qaaba-cai',//&id=be2us-64aaa-aaaaa-qaabq-cai',
{
methodName: 'get_counter',
arg: [],
},
)
console.log("get_counter " + JSON.stringify(get_counter))
But received error:
p: Server returned an error:
Code: 403 (Forbidden)
Body: Failed to authenticate request 0x625bed1a04f954c06475aacaff970bdf21134e6107d94bd350423676700e700f due to: Invalid delegation: Invalid canister signature: IcCanisterSignature signature could not be verified: public key
, error: certificate verification failed: failed to verify threshold signature: certificate_tree_hash=CryptoHash(0xf3cae2050e9bd2f25c6d3042ba97309536d55ab77674b6d3bdb39c416d38fac0), sig=Blob{48 bytes;ab4cadfc57c7014ad916aece2ac96e015f5e42596376b3c6c0548ee24f00605e492fbb7d9ba840bd52adb688bcb7adc6}, pk=ThresholdSigPublicKey { internal: ThresBls12_381(0xa2aac5e27aa6eef97624ba8fddb4c929eca7349ccef42302a8376a518afae90325be1d53e2d4eb27a29a0f698228194d12e3577451f3275b1e97b02633370edb7ed265de47dfd44ea781c1fecb37ce0273560aa4be7a4d9f1e6f6798ee65c06c) }, error=ThresBls12_381 signature could not be verified: public key